akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Stack;
public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        Stack<Integer> st = new Stack<>();
        int count = 0;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i) == '0') {
                st.push(0);
                count++;
            }
            else if(s.charAt(i) == '1') {
                st.push(1);
                count++;
            }
            else if(s.charAt(i) == 'B') {
                if(count == 0){
                    // do nothing
                } else {
                    st.pop();
                    count--;
                }
            }
        }
        for(int i=0; i<count; i++){
            System.out.print(st.get(i));
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<queue>
#include<map>
using namespace std;
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > q1;
int main(){
	int n;
	int a,b;
	int i,j,k;
	int s=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a;
		q1.push(make_pair(a,i));
	}
	for(i=0;i<n;i++){
		a=q1.top().first;
		j=q1.top().second;
		q1.pop();
		if((i+j)%2==1){
			s++;
		}
	}
	s/=2;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;
	cin >> n >> k;

	int cnt = 1;
	while(k<=n){
		n /= k;
		cnt++;
	}
	cout << cnt << endl;	
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int n, cut;
  int card_A[50], card_B[50], ans[10];
  int i, j;
  int p, c;

  while(1)
    {
      scanf(" %d %d", &n, &cut);
      if(n==0&&cut==0)
	{
	  break;
	}
      else
	{
	  for(i=0; i<=n-1; i++)
	    {
	      card_A[i]=n-i;
	    }

	  while(cut--)
	    {
	      scanf(" %d %d", &p, &c);

	      for(j=0; j<n; j++)
		{
		  card_B[j]=card_A[j];  //card_Bにコピー
		}

	      for(j=0; j<p-1; j++)
		{
		  card_B[j+c]=card_A[j];
		}

	      for(j=0; j<c;j++)
		{
		  card_B[j]=card_A[j+p-1];
		}

	      for(j=0; j<n;j++)
		{
		  card_A[j]=card_B[j]; //card_Aに入れ替えたものをコピー
		}
	
	    }
	}
      printf("%d\n" ,card_A[0]);
    }

}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9) cout << a * b << endl;
    else cout << -1 << endl;
}


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

using namespace std;

#define  N 1000100

typedef long long ll;
bool bad[10];

bool check(int x) {
    if (x==0 && bad[x]) return false;
    while (x > 0) {
        if (bad[x % 10]) return false;
        x /= 10;
    }
    return true;
}

void solve() {
    int x;
    cin >> x;
    int n;
    cin >> n;

    for (int i = 1; i <= n; i++) {
        int f;
        cin >> f;
        bad[f] = true;
    }

    for (int i = x;;i++) {
        if (check(i)) {
            cout << i << endl;
            return;
        }
    }

}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef qwerty
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

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

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	for (int i = 0; i < ty - sy; i++)
		cout << "U";
	for (int i = 0; i < tx - sx; i++)
		cout << "R";
	for (int i = 0; i < ty - sy; i++)
		cout << "D";
	for (int i = 0; i < tx - sx; i++)
		cout << "L";
	cout << "L";
	for (int i = 0; i < ty - sy + 1; i++)
		cout << "U";
	for (int i = 0; i < tx - sx + 1; i++)
		cout << "R";
	cout << "D";
	cout << "R";
	for (int i = 0; i < ty - sy + 1; i++)
		cout << "D";
	for (int i = 0; i < tx - sx + 1; i++)
		cout << "L";
	cout << "U" << endl;

    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 1e5 + 3;
int N;
LL C,x[MC],v[MC],s[MC],t[MC];

int main(){
	cin >> N >> C;
	repp(i,1,N+1){
		cin >> x[i] >> v[i];
		s[i] = s[i-1] + v[i];
	}
	repm(i,N,0) t[i] = t[i+1] + v[i];
	LL ans = 0;
	LL mx = 0;
	repm(i,N,0){
		ans = max(ans,s[i]-x[i]+mx);
		mx = max(mx,t[i]-2*(C-x[i]));
	}
	mx = 0;
	repp(i,1,N+1){
		ans = max(ans,t[i]-C+x[i]+mx);
		mx = max(mx,s[i]-2*x[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

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


vector<P> p(1000000);


int main(){
  int N;
  cin >> N;
  rep(i,N){
    int num;
    cin >> num;
    p[i] = make_pair(num,i);
  }
  p.resize(N);
  sort(p.begin(),p.end());
  rep(i,N) cout << ++p[i].second << " ";
  cout << endl;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char mp[1010][1010];
bool vis[1010][1010];
int main(){
    int h,w;scanf("%d%d",&h,&w);
    for(int i=1;i<=h;i++) scanf("%s",mp[i]+1);
    queue<pair<pair<int,int > ,int> > q;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++){
            if(mp[i][j]=='#'){
                q.push(make_pair(make_pair(i,j),0));
                vis[i][j]=1;
            }
        }
    }
    int ans=-1;
    while(!q.empty()){
        auto now=q.front();q.pop();
        int nowx=now.first.first;
        int nowy=now.first.second;
        int nowd=now.second;
        ans=nowd;
        for(int fx=-1;fx<=1;fx++)
        for(int fy=-1;fy<=1;fy++){
            if(fx*fy) continue;
            if(nowx+fx<1||nowx+fx>h) continue;
            if(nowy+fy<1||nowy+fy>w) continue;
            if(vis[nowx+fx][nowy+fy]) continue;
            vis[nowx+fx][nowy+fy]=1;
            q.push(make_pair(make_pair(nowx+fx,nowy+fy),nowd+1));
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 14352
import java.io.*;
import java.util.*;

public class Main {
    private ArrayList<ArrayList<Integer>> graph;
    public static void main(String[] args) throws Exception {
        new Main().solve();
    }

    private void solve() throws Exception{
        FastScanner scanner = new FastScanner(System.in);

        int V = scanner.nextInt();
        int E = scanner.nextInt();

        graph = new ArrayList<>(V);
        for(int i = 0; i < V; ++i){
            graph.add(new ArrayList<>());
        }

        int[] in = new int[V];
        for(int i = 0; i < E; ++i){
            int u = scanner.nextInt();
            int v = scanner.nextInt();

            graph.get(u).add(v);
            ++in[v];
        }

        LinkedList<Integer> queue = new LinkedList<>();
        for(int i = 0; i < V; ++i){
            if(in[i] == 0){
                queue.add(i);
            }
        }

        int count = 0;
        while(!queue.isEmpty()){
            int u = queue.remove().intValue();
            ++count;

            for(int v : graph.get(u)){
                --in[v];
                if(in[v] == 0){
                    queue.add(v);
                }
            }
        }

        if(count == V){
            System.out.println("0");
        }
        else {
            System.out.println("1");
        }
    }

    static class FastScanner {
        private InputStream in;
        private final byte[] buffer = new byte[1024 * 8];
        private int ptr = 0;
        private int buflen = 0;

        public FastScanner(InputStream in){
            this.in = in;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 25304
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    if(a == 'H')
    {
        cout << b << endl;
    }
    else
    {
        if(b == 'H') cout << 'D' << endl;
        else cout << 'H' << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: usize,
        s: Chars,
    }

    //let r = s.iter().filter(|&&x| x == 'r').count();
    //let g = s.iter().filter(|&&x| x == 'g').count();
    //let cb = s.iter().filter(|&&x| x == 'b').count();
    let mut r = vec![0u64; n + 1];
    let mut g = vec![0u64; n + 1];
    let mut b = vec![0u64; n + 1];

    for i in 0..n {
        r[i + 1] = r[i];
        g[i + 1] = g[i];
        b[i + 1] = b[i];
        if s[i] == 'R' {
            r[i + 1] += 1;
        }
        if s[i] == 'G' {
            g[i + 1] += 1;
        }
        if s[i] == 'B' {
            b[i + 1] += 1;
        }
    }
    //println!("{:?}", r);
    //println!("{:?}", g);
    //println!("{:?}", b);
    let mut ans = 0;

    for i in 0..n - 2 {
        for j in i + 1..n - 1 {
            if s[i] == s[j] {
                continue;
            }
            let check_k = 2 * j - i;
            match (s[i], s[j]) {
                ('R', 'G') | ('G', 'R') => {
                    ans += b[n] - b[j + 1];
                    if check_k < n && check_k > j {
                        if s[check_k] == 'B' {
                            ans -= 1;
                        }
                    }
                }
                ('G', 'B') | ('B', 'G') => {
                    ans += r[n] - r[j + 1];
                    if check_k < n && check_k > j {
                        if s[check_k] == 'R' {
                            ans -= 1;
                        }
                    }
                }
                ('B', 'R') | ('R', 'B') => {
                    ans += g[n] - g[j + 1];
                    if check_k < n && check_k > j {
                        if s[check_k] == 'G' {
                            ans -= 1;
                        }
                    }
                }
                _ => unreachable!(),
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2228
import itertools
n, m, q = map(int, input().split())
s = []
for i in range(q):
    s.append(list(map(int, input().split())))
a = list(itertools.combinations_with_replacement(range(1, m+1), n))
max_d = 0
for A in a:
    sum_d = 0
    for li in s:
        if A[li[1]-1] - A[li[0]-1] == li[2]:
            sum_d += li[3]
    max_d = max(max_d, sum_d)
print(max_d)

Measured memory_bytes: 21468
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]"):
    from collections import Counter
    c = Counter(A)

    # for k,v in c.items():
    #     print(k,v)
    
    m = sum([v for v in c.values()])
    cl = len([c for c in c.keys()])

    while(m > cl):
        m -= 2
    # if(m%3 == 0 or m%3 == 2):
    #     print(len(c.keys()))
    # elif(m%3 == 1):
    #     print(len(c.keys())-1)
    # else:
    #     print(len(c.keys())-1)
    print(m)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int S = A - B;
  
  if (S >= C) {
    cout << 0 << endl;
  } else {
    cout << C - S << endl;
  }
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
#include<math.h>

#define min (double)60
#define hour (double)12

typedef struct 
{
    double x; 
    double y;
} rect;


int main()
{
    double a, b, h, m, a_sita, b_sita;
    rect a_rect, b_rect;

    scanf("%lf %lf %lf %lf", &a, &b, &h, &m);

    b_sita = (-2*M_PI*m/min) + (M_PI/2);
    a_sita = (-2*M_PI*(h + (m/min))/hour) + (M_PI/2);

    a_rect.x = a*cos(a_sita);
    a_rect.y = a*sin(a_sita);

    b_rect.x = b*cos(b_sita);
    b_rect.y = b*sin(b_sita);

    printf("%.10lf", sqrt(pow((a_rect.x -b_rect.x),2.0) + pow((a_rect.y -b_rect.y),2.0)));

    return 0;
}

Measured memory_bytes: 2532
def main():

    from collections import Counter

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

    dp = [[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]
    c = Counter(a)

    # メモ化再帰ではpypy3でもTLEするのでforループを使う
    # j==k==0の場合を計算 → k==0の場合を計算 → 一般の場合を計算
    for k in range(c[3]+1):
        for j in range(c[3]+c[2]-k+1):
            for i in range(N-j-k+1):
                if i+j+k == 0:
                    continue
                else:
                    tmp = N
                    if i > 0: # IndexError防止
                        tmp += dp[i-1][j][k]*i
                    if j > 0:
                        tmp += dp[i+1][j-1][k]*j
                    if k > 0:
                        tmp += dp[i][j+1][k-1]*k
                    dp[i][j][k] = tmp/(i+j+k) # 割り算をまとめないとTLE

    print(dp[c[1]][c[2]][c[3]])

if __name__ == '__main__':
    main()

Measured memory_bytes: 599048
// ------------------------------------
// Date:2018/ 5/ 5
// Problem:/ / / a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

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

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

  CIN(a, b);
  int ans = a - 1;
  if (b >= a) ans++;
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstring>

const int MAXN = 100000 + 10;

int n;
char s[MAXN];

int main() {
	scanf("%s", s+1);
	n = strlen(s + 1);
	printf(((n & 1) ^ (s[1] == s[n])) ? "First\n" : "Second\n");
	return 0;
}

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

using namespace std;
typedef long long int ll;

#define p(V) for(int iiv=0;iiv<V.size();iiv++) cout<<V[iiv]<<" ";
#define mp make_pair
#define pb push_back
#define graph vector<vector<int> >
#define pf first
#define ps second
#define pq priority_queue
const int N = 2e5;
const int l = 18;
const double pi = acos(-1);
int n , w ;
ll dp[111][N] , ans;
vector<pair<int,int> > v;
int main(){   
    memset(dp,-1,sizeof dp);
    cin >> n >> w;
    v.resize(n);
    for(int i=0;i<n;i++) cin >> v[i].pf >> v[i].ps;
    for(int i=0;i<=w;i++) dp[n-1][i] = ((i>=v[n-1].pf)?v[n-1].ps:0) , ans=max(ans,dp[n-1][i]);
    for(int i=n-2;i>=0;i--) 
        for(int j=0;j<=w;j++){
            dp[i][j]=max(dp[i+1][j],dp[i][j]);
            if(j < v[i].pf) continue;
            dp[i][j]=max(dp[i+1][j-v[i].pf]+v[i].ps,dp[i+1][j]);
            ans=max(ans,dp[i][j]);
        }
    cout<<ans;
    return 0;
}


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

namespace AtCoder_Project_CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = int.Parse(Console.ReadLine());
            int max = 1;
            for (int i = 1; i <= x; i++)
            {
                for (int j = 2; j <= x; j++)
                {
                    int pow = (int)Math.Pow(i, j);
                    if (pow <= x)
                    {
                        if (max <= pow)
                        {
                            max = pow;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(max);
        }
    }
}


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

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int AC = 0, TLE = 0, WA = 0, RE = 0;
  for (int i = 0; i < n; i++) {
    string in;
    cin >> in;
    if (in == "AC") AC++;
    if (in == "TLE") TLE++;
    if (in == "WA") WA++; 
    if (in == "RE") RE++;
  }
  cout << "AC x " << AC << '\n' << "WA x " << WA << '\n' << "TLE x " << TLE << '\n' << "RE x " << RE << '\n';   
}            


Measured memory_bytes: 3640
#include <iostream>
using namespace std; typedef long long ll;

int main() {
  ll k,n; cin>>k>>n;
  ll a[n]; for(int i=0;i<n;i++) {cin>>a[i];}
  ll an=a[n-1]-a[0];
  for(int i=0;i<n-1;i++) {
    an = min(an, k + a[i] - a[i+1]);
  }
  cout<<an<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

typedef struct{
  short x,y;
  int cost;
  short ch;
}mouse;


mouse t;
short cx,cy,nx,ny,ch,nch,h,w,n;
int cost;

main(){
  scanf("%d%d%d",&h,&w,&n);
  short maxch[h][w];
  char ku[h][w];
  
  rep(i,h)scanf("%s",ku[i]);


  rep(i,h)rep(j,w){
    if(ku[i][j]=='S')cx=i,cy=j;
    maxch[i][j]=-1;
  }

  queue<mouse> Q;

  Q.push((mouse){cx,cy,0,0});
  maxch[cx][cy]=0;

  while(!Q.empty()){
    //cout<<Q.size()<<endl;
    t=Q.front();Q.pop();
    cx=t.x,cy=t.y,cost=t.cost;
    ch=t.ch;

    rep(i,4){
      nx=cx+dx[i],ny=cy+dy[i];
      if(nx<0 || nx>=h || ny<0 || ny>=w)continue;
	 if(ku[nx][ny]=='X')continue;
	 nch=ch;
	 if(ku[nx][ny]<='9' && ku[nx][ny]>='1' && ku[nx][ny]-'0'==t.ch+1){
	   nch=ch+1;
	 }

	 if(maxch[nx][ny]>=nch)continue;
	 if(nch==n){
	   printf("%d\n",cost+1);
	   return 0;
	 }
	 maxch[nx][ny]=nch;
	 Q.push((mouse){nx,ny,cost+1,nch});
    }
  }
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
/*                   وتزودوا فإن خير الزاد التقوى                    */
/*       وما تدري نفس ماذا تکسب غدا وما تدري نفس باي ارض تموت      */
#include <bits/stdc++.h>
#include<unordered_map>
#include<iomanip>
#include<fstream>
using namespace std;
#include<iostream>
#define endl '\n'
#define ll long long
#define ull unsigned long long
#define dll double
#define PI acos(-1)
#define watch(x) cout<<#x<<" = { "<<x<<" }\n"
#define sz(n) n.size()
#define M_Sayed fast() 
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define RT(v) return cout<<v,0
int dx[] = { 0, 1, 0, -1, 1, 1, -1, -1 };
int dy[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
const double EPS = (1e-7);
ll Ceil(ll x, ll y) { return (x + y - 1) / y; }
void run() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
#endif
}
ll gcd(ll a, ll b) { return !b ? abs(a) : gcd(b, a % b); }
ll lcm(ll a, ll b) { return abs(a / gcd(a, b)) * b; }
ll power(ll x, ll y, ll mod) {
	if (y == 0) return 1;
	if (y == 1) return x % mod;
	ll r = power(x, y >> 1, mod);
	return (((r * r) % mod) * power(x, y & 1, mod)) % mod;
}
void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
ll n, m, k,su,cnt;
ll vis[100009];
vector<ll>v;
ll Jum(int x) {
	if (x+1 == n)
		return 0;
	ll &ret = vis[x];
	if (~ret)return ret;
	 ret = abs(v[x] - v[x + 1])+Jum(x + 1) ;
	for (int i = 2; i <=k; i++) {
		if(i+x<n)ret = min(ret,Jum(x + i) + abs(v[x] - v[x + i]));
	}
	return ret;
}
int main()
{
	//run();
	M_Sayed;
	cin >> n ;
	memset(vis, -1, sizeof vis);
	v.resize(n);
	for (int i = 0; i <n; i++) {
		cin >> v[i];
	}
	k = 2;
	RT(Jum(0));
}

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

typedef long long ll;
const ll MOD = 1000000007;

ll modpow(ll x,ll k){
	if(k == 0)return 1;
	ll ret = modpow(x,k/2);
	ret *= ret; ret %= MOD;
	if(k%2 == 1){
		ret *= x;
		ret %= MOD;
	}
	return ret;
}

vector<ll> divisors(ll n){
	vector<ll> ret;
	ret.push_back(1);
	for(int i = 2 ; n > 1 ; i ++){
		if(i*i > n)i = n;
		if(n%i == 0){
			int cnt = 0;
			while(n%i == 0){
				n /= i;
				cnt ++;
			}
			int m = ret.size();
			ll x = 1;
			for(int j = 0 ; j < cnt ; j ++){
				x *= i;
				for(int i = 0 ; i < m ; i ++){
					ret.push_back(ret[i]*x);
				}
			}
		}
	}
	sort(ret.begin(),ret.end());
	return ret;
}

int main(){
	ll n,k;
	cin >> n >> k;
	
	vector<ll> div = divisors(n);
	ll ret = 0;
	ll cnt[1400];
	for(int i = div.size()-1 ; i >= 0 ; i --){
		ll d = div[i];
		if(d&1)cnt[i] = d;
		else cnt[i] = d/2;
		for(int j = i+1 ; j < div.size() ; j ++){
			if(div[j]%d == 0)cnt[i] += MOD-cnt[j];
		}
		ll sum = cnt[i]%MOD;
		sum *= modpow(k,(d+1)/2);
		ret += sum;
		ret %= MOD;
	}
	cout << ret << endl;
}



Measured memory_bytes: 256
from math import atan, degrees

a, b, x = map(int, input().split())
bottle = a ** 2 * b

ans = 0
if x >= bottle:
    ans = 0
elif x == bottle / 2:
    ans = 45
elif x > bottle / 2:
    h = (bottle - x) * 2 / (a ** 2)
    ans = degrees(atan(h / a))
else:
    h = x * 2 / (b * a)
    ans = degrees(atan(b / h))

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <vector>
#include <iomanip>
#include <limits>
using namespace std;

int main()
{
    int a, b, d, r;
    double f;
    cin >> a >> b;
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
    cout << fixed << d << " " << r << " " << std::setprecision(10) << f << endl;
    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  ll w,h,x,y;
  cin>>w>>h>>x>>y;
  double ans=0;
  if(w%2==0&&h%2==0){
    if(w/2==x&&h/2==y){
      ans=(double)w*h/2;
      cout<<ans<<" 1"<<endl;
      return 0;
    }
  }
  ans=(double)w*h/2;
  cout<<ans<<" 0"<<endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF = 2e9;
#define LINF = 1e18;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << = << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO")
#define Yes(n) cout << ((n) ? "Yes" : "No")

void input(vector<int> x, auto n){
   rep(i,n)cin >> x[i];
}

void PCes(){

    int h, w;
    cin >> h >> w;
    if(h == 0 && w == 0)return;
    rep(i, h){
        rep(j, w){
            if(i%2 == 1 && j%2 == 1 || i%2 == 0 && j%2 == 0)putchar('#');
            else putchar('.');
        }
        putchar('\n');
    }
    putchar('\n');
    return PCes();
}

int main(){
    PCes();
}


Measured memory_bytes: 3056
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    A = input().rstrip('\n')
    A = [int(a) for a in A]

    A = [abs(A[i+1] - A[i]) for i in range(N-1)]
    flg = 1
    if 1 not in A:
        flg = 2
        A = [a // 2 for a in A]
    else:
        A = [a % 2 for a in A]
    idx = []
    N -= 1
    for j in range(N.bit_length()):
        if N>>j&1:
            M = 2**j
            X = N%(M*2)
            if not idx:
                idx = list(range(M))
            else:
                idx_new = [X-1 - x for x in idx]
                idx.extend(idx_new)
    ans = 0
    #print(A)
    #print(idx)
    for i in idx:
        ans ^= A[i]
    print(ans * flg)


if __name__ == '__main__':
    main()


Measured memory_bytes: 131456
/*==============================================*\
ID:          shahidul_brur
 
Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh
 
 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = (int)2e5+5;
const int logn = 20;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n; string s;
    cin>>n>>s;
    if(n<3200) cout << "red";
    else cout << s;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
 
#define MOD (long long int)(1e9+7)
#define ll long long int


int main(void){
	
	char a,b;
	cin>>a>>b;
	if(a<b){
		cout<<"<"<<endl;
	}else if(a==b){
		cout<<"="<<endl;
	}else{
		cout<<">"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import collections
S=sorted(str(input()))
#print(*S)
A=[]
L = collections.Counter(S)
values, counts = zip(*L.most_common())
for i in range(len(values)):
  A.append(values[i])
A.sort()

x=0
for i in range(len(A)):
  if ord(A[i])!=i+97:
    x=i+97
    break
if x!=0:
  print(chr(i+97))    
else:
  if len(A)==25:
    print("z")
  else:
    print("None")

Measured memory_bytes: 4664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n-1);
  rep(i, n-1){
    cin >> a.at(i);
    a.at(i)--;
  }
  vector<int> ans(n, 0);
  rep(i, n-1){
    ans.at(a.at(i))++;
  }
  for(auto i : ans){
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 4828
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val a = (0 until m).map { 
        sc.nextInt()
     }

     abc129c(n, a)
}

fun abc129c(n: Int, a: List<Int>) {
    val safe = BooleanArray(n + 1) { true }
    for (ai in a) {
        safe[ai] = false
    }
    val mod: Long = (Math.pow(10.0, 9.0) + 7).toLong()
    val dp = LongArray(n + 1) { 0 }
    dp[0] = 1L
    if (safe[1]) dp[1] = 1L
    for (i in 2..n) {
        if (safe[i - 2]) dp[i] += dp[i - 2]
        if (safe[i - 1]) dp[i] += dp[i - 1]
        dp[i] %= mod
    } 
    val ans: Long = dp[n]
    println(ans)
}


Measured memory_bytes: 53536
s = input()
acgt = 'ACGT'

acgt_flag = False
length = 0
l = 0

for i in range(len(s)):
  if s[i] in acgt:
    if acgt_flag:
      l+=1
    else:
      l=1
      acgt_flag = True
  else:
    if acgt_flag:
      length = max(length, l)
      acgt_flag = False

length = max(length, l)
print(length)

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumlate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  string s; cin >> s;
  bool ans;

  int i = s.size();
  while(i >= 5){
    if(i - 5 >= 0)
      if(s.substr(i-5,5) == "dream"){
	i -= 5;
	continue;
      }else if(s.substr(i-5,5) == "erase"){
	i -= 5;
	continue;
      }
    if(i - 6 >= 0 and s.substr(i-6,6) == "eraser"){
      i -= 6;
      continue;
    }
    if(i - 7 >= 0 and s.substr(i-7,7) == "dreamer"){
      i -= 7;
      continue;
    }
    cout << "NO\n";
    return 0;
  }
  cout << "YES\n";
}


Measured memory_bytes: 512
import java.util.Scanner;

/**
 * Created by labuser on 2016/04/18.
 */
public class Main {
    public static void main(String[] args) {
    new Main().run();
    }

    private void run() {

        int a;
        int b;

        Scanner sc = new Scanner(System.in);
        String[] input = sc.nextLine().split(" ");
        a = Integer.parseInt(input[0]);
        b = Integer.parseInt(input[1]);

        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else if (a == b) {
            System.out.println("a == b");
        }

    }
}

Measured memory_bytes: 26084
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <atcoder/all>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
using namespace atcoder;
using mint = modint998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const int MODD = 998244353;
const ll LLINF = 1e18;

int op(int a, int b) { return max(a, b); }

int e() { return 0; }

segtree<int, op, e> seg(300100);
vector<int> ho(300100);

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

	seg.set(ho[0], 1);
	for (int i = 1; i < n; i++){
		seg.set(ho[i], 1 + seg.prod(max(0, ho[i]-k), min(300001, ho[i]+k)+1));
	}

	cout << seg.all_prod() << endl;
	return 0;
}


Measured memory_bytes: 8380
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int X;
    cin >> X;
    int MaxX = 0;
    int Y = 1;
    if(X == 1) cout << 1 << endl;
    else{
    for(int i = 2; i <= sqrt(X); i++){
        Y = 1;
        while(Y <= X){
            MaxX = max(MaxX,Y);
            Y *= i;
        }
    }
    cout << MaxX << endl;
    }
}


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

int main(void){
    ll n, m;
    cin >> n >> m;
    pair<bool, bool> path[n];
    rep(i, n){
        path[i] = {false, false};
    }

    rep(i, m){
        ll tmp_a, tmp_b;
        cin >> tmp_a >> tmp_b;
        tmp_a--;
        tmp_b--;
        if(tmp_a == 0)
            path[tmp_b].first = true;
        if(tmp_b == 0)
            path[tmp_a].first = true;
        if(tmp_a == n-1)
            path[tmp_b].second = true;
        if(tmp_b == n-1)
            path[tmp_a].second = true;
    }

    rep(i, n){
        if(path[i].first == true && path[i].second == true){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }


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


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long n;
    cin >> n;
    for(int i = 1;i<=3500;i++){
        for(int j = 1;j<=3500;j++){
            if(4*i*j-n*i-n*j>0){
                if((n*i*j)%(4*i*j-n*i-n*j)==0){
                    cout << i << " " << j << " " << (n*i*j)/(4*i*j-n*i-n*j) << endl;
                    return 0;
                }
            }
        }
    }
}

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

int main() {
    int N, K;
    std::cin >> N >> K;
    std::vector<int> A(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    /*
    O(K * N)解法
    「a以外の数字の組み合わせで作れる数字」を考えるため、両方向からdpテーブルを作る。
    */
    if (N == 1) {
        std::cout << 0 << std::endl;
        return 0;
    }
    /*
    dp1[i][k]: i番目（0-indexed）以前の数字の和でkを作れるか否か
    dp2[j][k]: j番目（0-indexed）以降の数字の和でkを作れるか否か
    iについてのfor loopで
        dp[j][k] = dp1[j][k] (j < i)
                 = dp2[j][k] (j >= i)
    となるように更新していく
    */
    std::vector<std::vector<int>> dp(N, std::vector<int>(K));
    // 最初はdp2で初期化
    dp[N - 1][0] = 1;
    if (A[N - 1] < K) {
        dp[N - 1][A[N - 1]] = 1;
    }
    for (int j = N - 2; j >= 0; j--) {
        for (int k = 0; k < K; k++) {
            dp[j][k] = dp[j + 1][k];
            if (k >= A[j]) {
                dp[j][k] = std::max(dp[j][k], dp[j + 1][k - A[j]]);
            }
        }
    }
    // 「A[i] 以外の数字の組で K-A[i] ～ K-1 は作れない」ものの数を数える
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (i == 0) {
            bool is_unnessesary = std::all_of(
                dp[1].begin() + std::max(0, K - A[i]),
                dp[1].begin() + K,
                [](int a) {return a == 0;});
            if (is_unnessesary) cnt += 1;
            // dp1の反映
            for (int k = 0; k < K; k++) {
                dp[0][k] = 0;
            }
            dp[0][0] = 1;
            if (A[i] < K) dp[0][A[i]] = 1;
        } else if (i == N - 1) {
            bool is_unnessesary = std::all_of(
                dp[N - 2].begin() + std::max(0, K - A[i]),
                dp[N - 2].begin() + K,
                [](int a) {return a == 0;});
            if (is_unnessesary) cnt += 1;
        } else {
            // dp2の累積和
            for (int k = 1; k < K; k++) dp[i + 1][k] += dp[i + 1][k - 1];
            bool is_unnessesary = true;
            for (int x = 0; x < K; x++) {
                if (dp[i - 1][x] == 0) continue;
                // K - A[i] - x <= y <= K - 1 - x なるyの存在をチェック
                if (0 < K - A[i] - x) {
                    // dp[i + 1]はdp2の累積和になっていることに注意
                    if (dp[i + 1][K - 1 - x] - dp[i + 1][K - A[i] - x - 1] > 0) {
                        is_unnessesary = false;
                        break;
                    }
                } else if (K - A[i] - x <= 0 && 0 <= K - 1 - x) {
                    // dp[i + 1]はdp2の累積和になっていることに注意
                    if (dp[i + 1][K - 1 - x] > 0) {
                        is_unnessesary = false;
                        break;
                    }
                }
            }
            if (is_unnessesary) cnt += 1;
            // dp1の反映
            for (int k = 0; k < K; k++) {
                dp[i][k] = dp[i - 1][k];
                if (k >= A[i]) dp[i][k] = std::max(dp[i][k], dp[i - 1][k - A[i]]);
            }
        }
   }
   std::cout << cnt << std::endl;
   return 0;
}

Measured memory_bytes: 101200
#include<stdio.h>
int main()
{

    int X,A,cons1=0,cons2=10;

    scanf("%d %d",&X,&A);

    if(X<A)
    {
        printf("%d\n\n",cons1);
       // printf("\n");
       // printf("%d is less than %d,so we should print %d.\n",X,A,cons1);
    }
    else
   {
        printf("%d\n",cons2);
       // printf("\n");
       // printf("%d is not less than %d,so we should print %d.\n",X,A,cons2);

   }
    return 0;

}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N),C(N-1);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];
    rep(i,N-1) cin >> C[i];

    int sum = 0;
    int count = 0;
    for(auto &a : A){    
        sum += B[a-1];
        if(count + 1 == a)sum += C[a-2];
        count = a;
    }
    cout << sum;
}


Measured memory_bytes: 256
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

const size = 1000000
var reader = bufio.NewReaderSize(os.Stdin,size)
func NextLine() string {
  var line,buffer []byte
  var isPrefix bool = true
  var err error
  for ;isPrefix; {
    line,isPrefix,err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
  }
  return string(buffer)
}
func NextInts() (int,int) {
  var x,y int
  var s []string = strings.Split(NextLine()," ")
  x,_ = strconv.Atoi(s[0])
  y,_ = strconv.Atoi(s[1])
  return x,y
}
func NextIntArray() []int {
  var s []string = strings.Split(NextLine()," ")
  var n int = len(s)
  var a []int = make([]int,n)
  for i:=0;i<n;i++ {
    a[i],_ = strconv.Atoi(s[i])
  }
  return a
}

func main() {
  var h,w int = NextInts()
  var a [][]int = make([][]int,h)
  for i:=0;i<h;i++ {
    a[i] = NextIntArray()
  }
  sets := Sets{}
  for i:=0;; {
    for j:=0;j<w-1;j++ {
      if a[i][j]%2 == 1 {
        sets = append(sets,Set{Point{i+1,j+1},Point{i+1,j+2}})
        a[i][j+1]++
      }
    }
    if i == h-1 { break }
    if a[i][w-1]%2 == 1 {
      sets = append(sets,Set{Point{i+1,w},Point{i+2,w}})
      a[i+1][w-1]++
    }
    i++
    for j:=w-1;j>0;j-- {
      if a[i][j]%2 == 1 {
        sets = append(sets,Set{Point{i+1,j+1},Point{i+1,j}})
        a[i][j-1]++
      }
    }
    if i == h-1 { break }
    if a[i][0]%2 == 1 {
      sets = append(sets,Set{Point{i+1,1},Point{i+2,1}})
      a[i+1][0]++
    }
    i++
  }
  fmt.Println(len(sets))
  for i:=0;i<len(sets);i++ {
    fmt.Println(sets[i].p1.x,sets[i].p1.y,sets[i].p2.x,sets[i].p2.y)
  }
}

type Point struct {
  x int
  y int
}
type Set struct {
  p1 Point
  p2 Point
}
type Sets []Set

Measured memory_bytes: 26880
#include<iostream>
#include<cstdio>
using namespace std;
const long long MOD=998244353;
const int MAX_N=101000;
long long pow_mod(long long a,long long n,long long m){
    long long ans=1;
    while(n){
        if(n&1){
            ans=(ans*a)%m;
        }
        a=(a*a)%m;
        n>>=1;
    }
    return ans;
}
long long sum[MAX_N];
int main(void){
	int n,i,x;
	int maxl=0;
	scanf("%d",&n);
	int flag=0;
	scanf("%d",&x);
	if(x==0)
	sum[x]++;
	else
	flag=1;
	for(i=2;i<=n;i++){
		scanf("%d",&x);
		sum[x]++;
		maxl=max(maxl,x);
		if(x==0)
		flag=1;
	}
	if(flag){
		printf("0\n");
		return 0; 
	}
	long long ans=1;
	for(i=1;i<=maxl;i++){
		ans=(ans*pow_mod(sum[i-1],sum[i],MOD))%MOD;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void);

main(){
  int a,b,c,d;
  scanf("%d %d",&a,&b);
  if(a<=1 || 1000000000<a || b<1 || 1000000000<b ) {
    printf("Error\n");
    return;
  }
  while(1){
    c = a/b;
    d = a - c*b;
    if(d == 0) break;
    a = b;
    b = d;
  }
  printf("%d\n",b);
return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

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

    int sol;
    if(K % 2 == 0){
        sol = (K / 2) * (K / 2);
    }else{
        sol = ((K + 1) / 2) * (K / 2);
    }
    printf("%d\n", sol);
    return 0;
}

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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;

class Line {
public:
	Point a, b;
};

ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point 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 (norm(b) < norm(c)) return -2;
	return 0;
}

bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - s.b) * cross(l.b - l.a, s.b - s.a) < eps);
}

bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

int main()
{
	int q;
	ld p1x, p1y, p2x, p2y, x, y;
	cout << fixed << setprecision(9);
	cin >> p1x >> p1y >> p2x >> p2y;
	Line l = { (Point) { p1x, p1y }, (Point) { p2x, p2y } };
	cin >> q;
	while (q--) {
		cin >> x >> y;
		Point p(x, y);
		Point res = proj(l, p) * (ld)2.0 - p;
		cout << res.real() << ' ' << res.imag() << endl;
	}
	return 0;
}

Measured memory_bytes: 3332
#include <iostream>
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)
using namespace std;

ll x[200000];
ll y[200000];

int main(){
  ll n;
  cin >> n;
  ll a;
  rep2(i, 1, n+1){
    cin >> a;
    if (i + a < n) x[i + a]++;
    if (i - a >= 0) y[i - a]++;
  }
  ll ans = 0;
  rep2(i, 2, n){
    ans += x[i] * y[i];
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 6720
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int n, m, x;
vector<int> cost_t(101, 0);

void make_cost_table()
{
  int a;
  REP(i, m) {
    cin >> a;
    cost_t[a] = 1;
  }
}

int get_left_cost()
{
  int cost = 0;
  for (int i = x; i >= 0; --i)
    cost += cost_t[i];
  return cost;
}

int get_right_cost()
{
  int cost = 0;
  for (int i = x; i <= n; ++i)
    cost += cost_t[i];
  return cost;
}

int main()
{
  cin >> n >> m >> x;
  make_cost_table();
  int right_cost = get_right_cost();
  int left_cost = get_left_cost();
  cout << min(right_cost, left_cost) << endl;
}


Measured memory_bytes: 256