akhauriyash/Code-Regression huggingface dataset:
import javax.management.MBeanRegistration;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.StringTokenizer;
import java.util.Scanner;
import java.lang.*;
import java.io.*;
import java.util.*;
import java.lang.Integer;
import java.util.HashMap;

public class Main {
    // driver function to test the above functions
    public static void main(String args[]) throws IOException {

        Reader.init(System.in);
        int n=  Reader.nextInt();
       int[] arr = new int[n];

       boolean[] veri = new boolean[n];
        for (int i=0; i<n-1
                ; i++){
            int val = Reader.nextInt();
            if (veri[val-1]==false){
                arr[val-1] = 1;
                veri[val-1]= true;
            }
            else {
            arr[val-1] = arr[val-1]+1;
            }
        }

        for (int i=0; i<n; i++){
            int val=0;
            if (veri[i]==false){
                val=0;
            }
            else {
                val= arr[i];
            }

            System.out.println(val);
        }

    }
}

class Node{
    char val;
    Node nxt = null;
    Node prev=null;


}



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

}

/** Class for buffered reading int and double values */
class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String next() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( next() );
    }

    static long nextLong() throws IOException {
        return Long.parseLong( next() );
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( next() );
    }

    static String line() throws IOException {
        return reader.readLine();
    }
}

Measured memory_bytes: 68000
s = input()
s_list = list(s)
out_list = []

for i in range(len(s_list)):
    if s_list[i] == "0":
        out_list.append("0")
    elif s_list[i] == "1":
        out_list.append("1")
    elif s_list[i] == "B":
        if out_list:
            del out_list[-1]

for ol in out_list:
    print(ol, end="")


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

int main() {
	int n;
    cin >> n;
    int a = 0;
    int w = 0;
    int t = 0;
    int r = 0;
    for(int i=0;i<n;i++){
      string s;
      cin >> s;
      if(s == "AC"){
        a++;
      }else if(s == "WA"){
        w++;
      }else if(s == "TLE"){
        t++;
      }else{
        r++;
      }
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;
  
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const double PI = acos(-1.0);

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(50) << setiosflags(ios::fixed);

  int a, b;
  cin >> a >> b;
  cout << a * b << " " << 2 * (a + b) << endl;
  return 0;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
using P = pair<ll, ll>;
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
template <class T> void scan(T a) { cin >> a; }
void scan(int &a) { cin >> a; }
void scan(long long &a) { cin >> a; }
void scan(char &a) { cin >> a; }
void scan(double &a) { cin >> a; }
void scan(long double &a) { cin >> a; }
void scan(char a[]) { scanf("%s", a); }
void scan(string &a) { cin >> a; }
template <class T> void scan(V<T> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T> void scan(V<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
template <class T> V<T> press(V<T> &x){ 
    V<T> res = x;
    sort(all(res));
    res.erase(unique(all(res)), res.end());
    REP(i, SZ(x)){
        x[i] = lower_bound(all(res), x[i]) - res.begin();
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

int main(){
    ios;
    INT(n);
    VEC(ll, a, n);
    ll now = 0, res = 0;
    REP(i, n) if(!chmax(now, a[i])) res += now - a[i];
    print(res);
}

Measured memory_bytes: 4752
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::sort;
using std::string;
using std::stringstream;
using std::vector;

int main()
{
    lint h, w, n;
    scanf("%lld", &h);
    scanf("%lld", &w);
    scanf("%lld", &n);

    vector<lint> a(n);

    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }

    vector<lint> color;
    for (int i = 0; i < n; ++i)
    {
        vector<lint> added(a[i], i + 1);
        color.insert(color.end(), added.begin(), added.end());
    }

    vector<vector<lint>> ans(h, vector<lint>(w, 0));

    lint mode = 1;
    lint row = 0;
    lint col = 0;

    for (auto c : color)
    {
        ans[row][col] = c;
        if (mode == 0 && col == 0)
        {
            mode = 1;
            row++;
        }
        else if (mode == 1 && col == w - 1)
        {
            mode = 0;
            row++;
        }
        else if (mode == 1)
        {
            col++;
        }
        else if (mode == 0)
        {
            col--;
        }
    }

    for (int i = 0; i < h; ++i)
    {
        stringstream ss;
        for (int j = 0; j < w; ++j)
        {
            ss << ans[i][j] << ' ';
        }
        std::cout << ss.str() << std::endl;
    }

    return 0;
}


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

using namespace std;
#define intMax 1000000000000;
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define be(a) (a.begin(), a.end())
#define rbe(p) (p.rbegin(), p.rend())
#define pb push_back

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, m;
    cin >> n >> m;
    vector<vector<char>> A(n + 1, vector<char>(m + 1, '*'));

    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            cin >> A[i][j];
        }
    }
    if (A[0][0] == '*')
    {
        cout << 0;
        return 0;
    }
    vector<vector<long long>> dp(n + 1, vector<long long>(m + 1));
    dp[0][0] = 1;
    rep(i, 0, n)
    {
        rep(j, 0, m)
        {
            if (i - 1 >= 0 && j - 1 >= 0 && A[i][j] != '#')
            {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
            else if (i - 1 >= 0 && A[i][j] != '#')
            {
                dp[i][j] = dp[i - 1][j];
            }
            else if (j - 1 >= 0 && A[i][j] != '#')
            {
                dp[i][j] = dp[i][j - 1];
            }
            dp[i][j] %= 1000000007;
        }
    }
    cout << dp[n - 1][m - 1];
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >> n;
    long long arr1[n];
    long long arr2[n]={0};
    for( int i = 0 ; i < n ; i++ ) 
    {
        cin >> arr1[i];
        arr2[i] = arr1[i];
        if( i > 0 )
        {
            if(arr1[i] < arr1[i-1]) arr1[i] = arr1[i-1];
        }
        //cout << arr1[i] << " ";
    }
    //cout << "\n";
    long long count = 0;
    for( int i = 0 ; i < n ; i++ )
    {
        count += arr1[i]-arr2[i];
    }
    cout << count;
}

Measured memory_bytes: 6680
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

using namespace std;
using ll = long long;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    int N, W;
    cin >> N >> W;
    vector<pair<int, int>> wv(N);
    cin >> wv;
    vector<vector<ll>> dp(N + 1, vector<ll>(100 * 1000 + 100, INF));
    dp[0][0] = 0;
    REP(i, N) {
        REP(v, 100 * 1000 + 1) {
            chmin(dp[i + 1][v], dp[i][v]);
            if (v - wv[i].second < 0)continue;
            chmin(dp[i + 1][v], dp[i][v - wv[i].second] + wv[i].first);
        }
    }

    int ans = 0;
    REP(i, 100 * 1000 + 1) {
        if (dp[N][i] > W || dp[N][i] <= 0)continue;
        chmax(ans, i);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    const double pi = 3.141592653589;
    int a,b,c;
    scanf("%d%d%d", &a,&b,&c);
    double S = a*b*sin(c*pi/180)/2;
    double LL = a*a + b*b - 2*a*b*cos(c*pi/180);
    double L = sqrt(LL)+a+b;
    double h = b*sin(c*pi/180);
    printf("%lf\n%lf\n%lf\n", S,L,h);
}


Measured memory_bytes: 3336
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];

    deque<int> dq;
    rep(i,n){
        int p = lower_bound(ALL(dq),a[i]) - dq.begin();
        // a[i]以上の最初の添字
        if(p==0)dq.push_front(a[i]);
        else dq[p-1] = a[i];
    }
    cout << dq.size() << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll n,d;
	cin>>n>>d;
	int ans=0;
	for (int i=1;i<=n;i++){
		ll x,y;
		cin>>x>>y;
		if (x*x+y*y<=d*d) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3612
s=str(input())
s=list(s)
if "W" in s and "E" not in s:
  print("No")
elif "E" in s and "W" not in s:
  print("No")
elif "N" in s and "S" not in s:
  print("No")
elif "S" in s and "N" not in s:
  print("No")
else:
  print("Yes")

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

using namespace std;

int n;
int a[200][200];
int dp[200][200];

void dfs(int nowx,int nowy,int c) {
    if (nowy >= 2) return;
    if (nowx >= n) return;
    if (dp[nowy][nowx] < c) dp[nowy][nowx] = c;
    dfs(nowx,nowy+1,c+a[nowy+1][nowx]);
    dfs(nowx+1,nowy,c+a[nowy][nowx+1]);
    return;
}


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

    for(int i = 0;i < 2;i++){
        for(int j = 0;j < n;j++){
            cin >> a[i][j];
        }
    }

    dfs(0,0,a[0][0]);

    cout << dp[1][n-1] << endl;

    return 0;

}

Measured memory_bytes: 256
import sys
n = int(input())
road = [0]*n
for i in range(n):
  road[i] = [int(x) for x in input().split()]

road_judge = [[True]*n for i in range(n)]
for k in range(n):
  for i in range(n):
    for j in range(n):
      if road[i][j] > road[i][k]+road[k][j]:
        print(-1)
        sys.exit()
      if road[i][j] == road[i][k]+road[k][j] and i != k and j != k:
        road_judge[i][j] = False
ans = 0
for i in range(n):
  for j in range(n):
    if road_judge[i][j]:
      ans += road[i][j]
print(ans//2)

Measured memory_bytes: 44764
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <queue>
#include <iostream>
using namespace std;
#define lol long long

int n,m,k,x,f[100],ans;

inline int read()
{
	int x = 0 , f = 1;char ch = getchar();
	while (ch < '0' || ch > '9') {if (ch == '-') f = -1;ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = (x << 1) + (x << 3) + (ch ^ 48);ch = getchar();}
	return x * f;
}
inline void out(int x)
{
	if (x < 0) putchar('-'),x=-x;
	if (x > 9) out(x / 10);
	putchar(x % 10 + 48);
}

int main()
{
	n=read(),m=read();
	for (int i=1; i<=n; i++)
	{
		k=read();
		for (int j=1; j<=k; j++)
		{
			x=read();
			f[x]++;
		}
	}
	for (int i=1; i<=m; i++)
		if (f[i]==n) ans++;
	out(ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main() {
  vector<int> a(10);
  int max;
  size_t idx;
  vector<int>::iterator itr;
  
  for(size_t i = 0; i < a.size(); ++i) {
	cin >> a[i];
  }

  for(int i = 0; i < 3; i++) {
	itr = max_element(a.begin(), a.end());
	idx = distance(a.begin(), itr);
	cout << *max_element(a.begin(), a.end()) << endl;
	a[idx] = 0;
  }
  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

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

const ll MOD = 1000000007;


int main() {
	ll a, b, ans=0;
	cin >> a >> b;
	if (a == 1 && b == 1) {
		cout << 1 << endl;
	}
	else if (a == 1 || b == 1) {
		ll l = max(a, b);
		cout << l - 2;
	}
	else if (a == 2 || b == 2) {
		cout << 0 << endl;
	}
	else {
		cout << (a - 2)*(b - 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
        String t = sc.next();
		int ans = 0;
        for(int i=0;i<3;i++){if(s.charAt(i)==t.charAt(i)){ans++;}                                                                      
                            }       
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)
char mp[400][400];
ll c1=0;
ll c2=0;
std::vector<int> dx={1,0,-1,0};
std::vector<int> dy={0,1,0,-1};
int h,w;
void search(int i, int j, std::vector<int>& colors, std::vector<bool>& visited) {
  if(visited[i*w+j])
    return;
  visited[i*w+j]=true;
  if(colors[i*w+j]==1)
    c1++;
  else
    c2++;
  rep(k,4) {
    int ii=i+dx[k];
    int jj=j+dy[k];
    if(0<=ii&&ii<h&&0<=jj&&jj<w&&mp[i][j]!=mp[ii][jj])
      search(ii,jj,colors,visited);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cin>>h>>w;
  rep(i,h) {
    string s;
    cin>>s;
    rep(j,w) {
      mp[i][j]=s[j];
    }
  }
  vector<int> colors(h*w); // 1 = #, 0='.'
  rep(i,h) {
    rep(j,w) {
      if(mp[i][j]=='#')
        colors[i*w+j]=1;
      else
        colors[i*w+j]=0;
    }
  }
  vector<bool> visited(h*w);
  ll ans=0;
  rep(i,h) {
    rep(j,w) {
      if(!visited[i*w+j]) {
        c1=0;
        c2=0;
        search(i,j,colors,visited);
        ans+=(c1*c2);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13568
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
max_a = sorted(a,reverse=True)[:3]
if(max_a[0] > max_a[1]):
    for i in range(N):
        if(a[i] == max_a[0]):
            print(max_a[1])
        else:
            print(max_a[0])
else:
    for i in range(N):
        print(max_a[0])




Measured memory_bytes: 13340
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int N, K;
int T[100010];

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

    cin >> N >> K;
    REP(i, N) cin >> T[i];
    vector<pair<int, int>> v;
    v.emplace_back(T[0], T[0] + 1);
    FOR(i, 1, N) {
        if (v.back().second == T[i]) {
            auto p = v.back();
            v.pop_back();
            v.emplace_back(p.first, T[i] + 1);
        } else {
            v.emplace_back(T[i], T[i] + 1);
        }
    }
    int ans = N;
    vector<int> w;
    REP(i, v.size() - 1) w.emplace_back(v[i + 1].first - v[i].second);
    sort(w.begin(), w.end());
    int sz = min((int)w.size(), (int)v.size() - K);
    REP(i, sz) {

        ans += w[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 7064
#include <stdio.h>



int main() {
    int N;
    long K;
    scanf("%d", &N);
    scanf("%ld", &K);


    int A[N+1];
    int check[N+1];
    for (int i = 1; i < N+1; i++) {
        scanf("%d", &A[i]);
        check[i] = 0;
    }

    //printf("%d %ld\n", N, K);
    //for (int i = 1; i < N+1; i++) {
    //    printf("A[%d]: %d\n", i, A[i]);
    //}

    int ans = 0;;
    // 周期を見つける
    int start = 1;
    int next = A[start];
    check[start] = 0;
    check[next] = 1;
    int M = 2;
    if (K == 1) {
        ans = next;
        printf("%d\n", ans);
        return 0;
    }
    for (int i = 2; i < K + 1; i++) {
        next = A[next];
        if (i == K) {
            printf("%d\n", next);
            return 0;
        }
        if (check[next] >= 1) {
            break;
        }
        check[next] = i;
        M++;
    }

    //printf("untile loop %d\n", check[next]); // ループの開始に到達するまでのステップ数
    //printf("loop %d\n", M - check[next]); // ループ数

    int count = (K - check[next]) % (M - check[next]);
    if (count == 0) {
        printf("%d\n", next);
    } else {
        for (int i = 1; i < count + 1; i++) {
            next = A[next];
        }
        printf("%d\n", next);
    }

    return 0;
}


Measured memory_bytes: 3292
from random import randint
import sys
input = sys.stdin.readline
INF = 9223372036854775808


def calc_score(D, C, S, T):
    """
    開催日程Tを受け取ってそこまでのスコアを返す
    コンテストi 0-indexed
    d 0-indexed
    """
    score = 0
    last = [0]*26  # コンテストiを前回開催した日
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]
    return score


def update_score(D, C, S, T, score, ct, ci):
    """
    ct日目のコンテストをコンテストciに変更する
    スコアを差分更新する

    ct: change t 変更日 0-indexed
    ci: change i 変更コンテスト 0-indexed
    """
    new_score = score
    last = [0]*26  # コンテストiを前回開催した日
    prei = T[ct]  # 変更前に開催する予定だったコンテストi
    for d, t in enumerate(T, start=1):
        last[t] = d
        new_score += (d - last[prei])*C[prei]
        new_score += (d - last[ci])*C[ci]
    last = [0]*26
    for d, t in enumerate(T, start=1):
        if d-1 == ct:
            last[ci] = d
        else:
            last[t] = d
        new_score -= (d - last[prei])*C[prei]
        new_score -= (d - last[ci])*C[ci]
    new_score -= S[ct][prei]
    new_score += S[ct][ci]
    return new_score


def evaluate(D, C, S, T, k):
    """
    d日目終了時点での満足度を計算し，
    d + k日目終了時点での満足度の減少も考慮する
    """
    score = 0
    last = [0]*26
    for d, t in enumerate(T):
        last[t] = d + 1
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
        score += S[d][t]

    for d in range(len(T), min(len(T) + k, D)):
        for i in range(26):
            score -= (d + 1 - last[i]) * C[i]
    return score


def greedy(D, C, S):
    Ts = []
    for k in range(5, 13):
        T = []  # 0-indexed
        max_score = -INF
        for d in range(D):
            # d+k日目終了時点で満足度が一番高くなるようなコンテストiを開催する
            max_score = -INF
            best_i = 0
            for i in range(26):
                T.append(i)
                score = evaluate(D, C, S, T, k)
                if max_score < score:
                    max_score = score
                    best_i = i
                T.pop()
            T.append(best_i)
        Ts.append((max_score, T))
    return max(Ts, key=lambda pair: pair[0])


def local_search(D, C, S, score, T):
    # ct 日目のコンテストをciに変更
    for k in range(50000):
        ct = randint(0, D-1)
        ci = randint(0, 25)
        ori = T[ct]
        new_score = update_score(D, C, S, T, score, ct, ci)
        T[ct] = ci
        if score < new_score:
            score = new_score
        else:
            T[ct] = ori
    return T


if __name__ == '__main__':
    D = int(input())
    C = [int(i) for i in input().split()]
    S = [[int(i) for i in input().split()] for j in range(D)]
    init_score, T = greedy(D, C, S)
    T = local_search(D, C, S, init_score, T)
    for t in T:
        print(t+1)


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

using namespace std;

int main() {
	int x, y;
	string s;

	cin >> s;
	cin >> x >> y;

	if (s.back() == 'F') s += 'T';

	int N = s.size();
	vector<vector<bool>> dpx(2, vector<bool>(2 * N + 2, false));
	vector<vector<bool>> dpy(2, vector<bool>(2 * N + 2, false));

	int idx = 0, d = 0, dir = 0;//dir  0:左右 1:上下
	while (idx < N && s[idx] == 'F') {
		idx++; d++;
	}
	//dp初期化
	dpx[idx % 2][N + d] = dpy[idx % 2][N] = true;

	//配列の位置保持
	int src = idx % 2, dst = (src + 1) % 2;

	while (idx < N) {
		//目的地初期化
		fill(dpx[dst].begin(), dpx[dst].end(), false);
		fill(dpy[dst].begin(), dpy[dst].end(), false);

		//文字がT
		if (s[idx] == 'T') {
			//行くことのできる位置は変化しない
			for (int i = 0; i < 2 * N + 2; i++) {
				dpx[dst][i] = dpx[src][i];
				dpy[dst][i] = dpy[src][i];
			}
			//次に移動する方向を保持
			dir = (dir + 1) % 2;
		}
		else {
			//移動距離計算
			d = 0;
			while (idx < N && s[idx] == 'F') {
				idx++; d++;
			}
			idx--; //Tに来ているので戻す

			//移動する
			for (int i = 0; i < 2 * N + 2; i++) {
				//左右or上下に移動
				if (dir == 0) {
					if (i - d >= 0) dpx[dst][i - d] = dpx[dst][i - d] || dpx[src][i];
					if (i + d < 2 * N + 2) dpx[dst][i + d] = dpx[dst][i + d] || dpx[src][i];
					//移動しない方はそのままを維持
					dpy[dst][i] = dpy[src][i];
				}
				else {
					if (i - d >= 0) dpy[dst][i - d] = dpy[dst][i - d] || dpy[src][i];
					if (i + d < 2 * N + 2) dpy[dst][i + d] = dpy[dst][i + d] || dpy[src][i];
					//移動しない方はそのままを維持
					dpx[dst][i] = dpx[src][i];
				}
			}
		}
		idx++;
		int tmp = src;
		src = dst;
		dst = tmp;
	}

	x += N; y += N;
	if (dpx[src][x] && dpy[src][y])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 240000;

int main()
{
    int n;
    while (cin >> n && n != 0)
    {
        vector<int> table(MAX, 0);
        for (int i = 0; i < n; i++)
        {
            string start, end;
            cin >> start >> end;
            start.erase(remove(start.begin(), start.end(), ':'), start.end());
            end.erase(remove(end.begin(), end.end(), ':'), end.end());

            int int_start = stoi(start);
            int int_end = stoi(end);

            table[int_start]++;
            table[int_end]--;
        }

        vector<int> sum(MAX, 0);
        int tmp_ans = 0;
        for (int i = 0; i < MAX; i++)
        {
            sum[i + 1] = sum[i] + table[i];
            tmp_ans = max(tmp_ans, sum[i + 1]);
        }

        cout << tmp_ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4860
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    ll N;
    ll ans=0;
    ll ilog=0;
    cin>>N;
    for(ll i=1;(i*i)<=N;i++){
        ilog=i;
    }
    for(ll j=ilog;j>1;j--){
        if(N%j==0){
            ans=j-1+(N/j)-1;
            Out(ans);
            return 0;
        }
    }
    ans+=N-1;
    Out(ans);
    return 0;
}

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

#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)

using namespace std;

inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);


    
    int n=rr,x;
    set<int>S;

    loop(i,n){
        x=rr;
        S.insert(x);
    }

    int dif = n-S.size();

    if(dif%2)cout << S.size()-1 << endl;
    else cout << S.size() << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}



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

    ans += -(N - (K - 1)) * ((N - (K - 1)) + 1) * (2 * (N - (K - 1)) + 1) / 6 + (N - 2 * K + 1) * (N - (K - 1)) * ((N - (K - 1)) + 1) / 2 + ((N - (K - 1)) + 1) * (-(K - 1) * (K - 1) + (N - 1) * (K - 1) + N + 1);

    ans %= ll(1e9) + 7;

    cout << ans << endl;
}


Measured memory_bytes: 3600
str = input()
q = int(input())
for i in range(q):
    order = input().split()
    a = int(order[1])
    b = int(order[2])+1
    if order[0] == "print":
        print(str[a:b])
    elif order[0] == "reverse":
        str = str[:a] + str[a:b][::-1] + str[b:]
    elif order[0] == "replace":
        p = order[3]
        str = str[:a] + p + str[b:]
    order = []



Measured memory_bytes: 5616
fun main(args: Array<String>) {
    val (N, K) = readInputLine().split(" ").map { it.toInt() }
    val HList = readInputLine().split(" ").map { it.toLong() }.sortedDescending()

    if (K >= N) {
        println(0)
    } else {
        println(HList.drop(K).sum())
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

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

Measured memory_bytes: 256
<?php

// ITP1_11 Dice IV

// read data
$n = trim(fgets(STDIN));
$data = [];
for ($i = 0; $i < $n; $i++) {
  $input = trim(fgets(STDIN));
  $labels = explode(" ", $input);
  $data[] = $labels;
}

usort($data, 'compare');

// check
$cmp = false;
for ($i = 0; $i < $n-1 and !$cmp; $i++) {
  $dice1 = new Dice($data[$i]);
  $a = $data[$i];
  sort($a);
  for ($j = $i + 1; $j < $n and !$cmp; $j++) {
    $b = $data[$j];
    sort($b);
    if (!array_diff_assoc($a, $b)) {
      $dice2 = new Dice($data[$j]);
      $cmp = compare_dice($dice1, $dice2);
      // var_dump($cmp);
    }
  }
}

// answer
if ($cmp) {
  echo "No" . PHP_EOL;
} else {
  echo "Yes" . PHP_EOL;
}

//========================================

function print_labels(array $data) {
  foreach ($data as $labels) {
    echo implode(",", $labels) . PHP_EOL;
  }
}

function compare($arr_a, $arr_b)
{
  $sum_a = array_sum($arr_a);
  $sum_b = array_sum($arr_b);

  if ($sum_a == $sum_b) {
    return 0;
  } else {
    return ($sum_a < $sum_b) ? -1 : 1;
  }
}

function compare_dice($dice1, $dice2)
{
  $dice1_top = $dice1->getLabel("T");

  $check_dirs = "NWSSSW";
  foreach (str_split($check_dirs) as $dir)
  {
    $dice2->roll($dir);
    $dice2_top = $dice2->getLabel("T");
    if ($dice1_top == $dice2_top) {
      for ($i = 0; $i < 4; $i++) {
        if ($dice1->isEqual($dice2)) {
          return true;
        }
        $dice2->roll("R");
      }
    }
  }
  return false;
}


//========================================

class Dice
{
  private $labels;
  private $TBL_ROLL = array(
    array(4, 0, 2, 3, 5, 1),  // -> S
    array(3, 1, 0, 5, 4, 2),  // -> E
    array(2, 1, 5, 0, 4, 3),  // -> W
    array(1, 5, 2, 3, 0, 4),  // -> N
    array(0, 3, 1, 4, 2, 5),  // -> sidespin : right
    array(0, 2, 4, 1, 3, 5)   // -> sidespin : left
  );

  public function __construct($labels)
  {
    $this->labels = $labels;
  }

  public function roll($dirs)
  {
    foreach (str_split($dirs) as $dir) {
      $idx = strpos("SEWNRL", $dir);
      if ($idx === false) {
        continue;
      }

      $old = $this->labels;
      for ($i = 0; $i < 6; $i++) {
        $this->labels[$i] = $old[$this->TBL_ROLL[$idx][$i]];
      }
    }
  }

  public function isEqual($dice) {
    return ($this->labels == $dice->getLabels());
  }

  public function getLabel($dir) {
    $idx = strpos("TSEWNB", $dir);
    if ($idx !== false) {
      return $this->labels[$idx];
    }
    return false;
  }

  public function getLabels() {
    return $this->labels;
  }

  public function getDirection($number) {
    $idx = array_search($number, $this->labels);
    if ($idx !== false) {
      return "TSEWNB"[$idx];
    }
    return false;
  }
}

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

namespace AtCoder.Contest.C
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			var a = cin.ArrayLong(n + 1);
			long sum = a.Sum();
			long ans = 0;

			long leftnode = 1;
			bool ok = true;
            for (int i = 0; i < n + 1; i++)
            {
				leftnode -= a[i];
				if (leftnode >= 100000000) break;
				if (leftnode < 0)
				{
					ok = false;
					break;
				}
				leftnode *= 2;
            }

			long available = 1;
			if (!ok) Console.WriteLine(-1);
			else
			{
				for (int i = 0; i < n + 1; i++)
				{
					if (available < 1000000000000000L)
					{
						ans += Math.Min(available, sum);
						sum -= a[i];
						available -= a[i];
						available *= 2;
					}
					else
					{
						ans += sum;
						sum -= a[i];
					}
				}

				Console.WriteLine(ans);
			}

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 37064
N = int(input())
A = input().split()
A = [int(s) for s in A]

sum = 1

if 0 in A:
    sum = 0

else:
    for i in range(len(A)):
        sum *= A[i]
        if sum > 1000000000000000000:
            break
    
if sum > 1000000000000000000:
    sum = -1

print(sum)

Measured memory_bytes: 21476
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int r,c,n,i,j,top,x,y,zhan[200005],book[100005],top2;
struct nyh{
	int x,y,id;
}o[200005];
bool cmp(nyh u,nyh v){
	return u.id<v.id||u.id==v.id&&u.x<v.x;
}
int main(){
    //freopen("teleports.in","r",stdin);
    //freopen("teleports.out","w",stdout);
    r=read();c=read();n=read();
    for(i=1;i<=n;i++){
    	x=read();y=read();
    	
    		if(y==0){
				top++;
				o[top].x=x;
				o[top].id=1;
				o[top].y=i;
			}		
			else if(x==r){
				top++;
				o[top].x=y;
				o[top].id=2;
				o[top].y=i;
			}
			else if(y==c){
				top++;
				o[top].x=-x;
				o[top].id=3;
				o[top].y=i;
			}
			else if(x==0){
				top++;
				o[top].x=-y;
				o[top].id=4;
				o[top].y=i;
			}
		
		x=read();y=read();
    	if(top&1){
			if(y==0){
				top++;
				o[top].x=x;
				o[top].id=1;
				o[top].y=i;
			}		
			else if(x==r){
				top++;
				o[top].x=y;
				o[top].id=2;
				o[top].y=i;
			}
			else if(y==c){
				top++;
				o[top].x=-x;
				o[top].id=3;
				o[top].y=i;
			}
			else if(x==0){
				top++;
				o[top].x=-y;
				o[top].id=4;
				o[top].y=i;
			}
			else{
				o[top].x=0;
				o[top].y=0;
				o[top].id=0;
				top--;
			}
		}
	}
	sort(o+1,o+top+1,cmp);
	for(i=1;i<=top;i++){
		if(book[o[i].y]==0){
			book[o[i].y]=1;
			top2++;
			zhan[top2]=o[i].y;
		}
		else if(book[o[i].y]==1){
			if(zhan[top2]==o[i].y)
				top2--;
			else{
				printf("NO\n");
				return 0;
			}
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 3200
n,k=map(int,input().split())

import math
import numpy as np
def lambda_p(k,n):
  m=math.ceil(math.log(k,2))
  p=0
  for ii in np.arange(1,n+1):
    p+=1/n*(1/2)**math.ceil(math.log(k/ii,2))
  return p

def lambda_nk(n,k):
  return k/n

if n>k:
  r=lambda_nk(n,k)*lambda_p(k,k)+(1-lambda_nk(n,k))
else:
  r=lambda_p(k,n)
print(r)

Measured memory_bytes: 12500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 2147483647;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLMAX = 9223372036854775805;

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 / gcd(a, b) * b;} //最大公約数

int main(){
    ll x;
    cin >> x;
    cout << lcm(x,360) / x << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=-10000000000;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	vector<ll> A(N);
	rep(i,N) cin>>A[i];
	//偶数和を＋
	ll cnt=max((ll)1,A[0])-A[0];
	ll sum=max((ll)1,A[0]);
	rep1(i,N-1){
		sum+=A[i];
		if(i%2==0){
			if(sum<=0){
				cnt+=1-sum;
				sum=1;
			}
		}
		else{
			if(sum>=0){
				cnt+=1+sum;
				sum=-1;
			}
		}
	}
	ll ans=cnt;
	//偶数和をー
	cnt=abs(min((ll)(-1),A[0])-A[0]);
	sum=min((ll)(-1),A[0]);
	rep1(i,N-1){
		sum+=A[i];
		if(i%2==0){
			if(sum>=0){
				cnt+=1+sum;
				sum=-1;
			}
		}
		else{
			if(sum<=0){
				cnt+=1-sum;
				sum=1;
			}
		}
	}
	cout<<min(ans,cnt);
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

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

int H, W, K;
char c[810][810];
int sx, sy;
int d[810][810];

int main() {
	scanf("%d %d %d", &H, &W, &K);
	memset(d, -1, sizeof(d));
	queue<pii> que;

	rep(i, H) {
		scanf("%s", c[i]);
		rep(j, W) {
			if (c[i][j] == 'S') {
				sy = i;
				sx = j;
				c[i][j] = '.';
				que.push(mp(i, j));
				d[i][j] = 0;
			}
		}
	}

	int ret = 100000;

	while (!que.empty()) {
		pii p = que.front(); que.pop();
		int y = p.fi, x = p.se;
		if (d[y][x] > K) break;

		int t = min({y, x, H-1-y, W-1-x});
		ret = min(ret, (t + K  - 1) / K + 1);

		rep(i, 4) {
			int ny = y + dy[i], nx = x + dx[i];
			if (ny >= 0 && ny < H && nx >= 0 && nx < W && c[ny][nx] == '.' && d[ny][nx] == -1) {
				d[ny][nx] = d[y][x] + 1;
				que.push(mp(ny, nx));
			}
		}
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>
#include<queue>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000001
using namespace std;
typedef long long ll;

typedef pair<int, int> P;
int h,w;
char s[100][100];
int d[100][100];
int sy, sx;
int gy, gx;

int bfs(int y,int x){
  int dy[4] = {1,0,-1,0};
  int dx[4] = {0,1,0,-1};

  rep(i,1,h+1){
    rep(j,1,w+1){
      d[i][j] = MAX;
    }
  }
  d[y][x] = 1;
  queue<P> q;
  q.push(P(y,x));
  while(q.size()){
    P corrent = q.front();q.pop();
    // std::cout << corrent.first<<corrent.second << '\n';
    if(corrent.first==gy&&corrent.second==gx)break;
    rep(i,0,4){
      int ny = corrent.first+dy[i]; int nx = corrent.second+dx[i];
      if(0<ny && ny<=h && 0<nx && nx<=w && s[ny][nx]=='.' && d[ny][nx]==MAX){
        d[ny][nx] = d[corrent.first][corrent.second]+1;
        q.push(P(ny,nx));
      }
    }
  }
  return d[gy][gx];
}
int count_sharp(){
  int cnt = 0;
  rep(i,1,h+1){
    rep(j,1,w+1){
      if(s[i][j] == '#')cnt++;
    }
  }
  return cnt;
}

int main(){
  std::cin >> h>>w;
  rep(i,1,h+1){
    rep(j,1,w+1){
      std::cin >> s[i][j];
    }
  }
  // std::cout << "/* message */" << '\n';
  sy=1;sx=1;
  gy=h;gx=w;
  int min_d = bfs(sy,sx);
  if(min_d != MAX)std::cout << (h*w - count_sharp() - min_d) << '\n';
  else std::cout << "-1" << '\n';

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, ns, ne) for (int i = ns; i < ne; ++i)
using namespace std;
int main() {
  vector<int> v(3);
  rep(i, 0, 3) { cin >> v[i]; }
  sort(v.begin(), v.end());
  cout << ((v[0] + v[1] == v[2]) ? "Yes" : "No") << endl;
  getchar();
}

Measured memory_bytes: 3636
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new aoj0223().doIt();
    }
    class aoj0223{
    	int mx[] = {0,1,0,-1};
    	int my[] = {1,0,-1,0};
    	boolean map[][] = new boolean[53][53];
    	class Par{
    		int x,y;
    		public Par(int x,int y){
    			this.x = x;
    			this.y = y;
    		}
    	}
    	ArrayList<Par> array = new ArrayList<Par>();
    	ArrayList<Par> array2 = new ArrayList<Par>();
    	TreeSet<String> ts = new TreeSet<String>();
    	int roop(int x,int y){
    		for(int i = 0;i < 101;i++){
    			int length = array.size();
//    			System.out.println(i);
    			for(int j = 0;j < length;j++){
    				Par p = array.remove(0);
    				Par p2 = array2.remove(0);
    				int sx = p.x;
    				int sy = p.y;
    				int ex = p2.x;
    				int ey = p2.y;
    				if(sx == ex && sy == ey)return i;
            		for(int k = 0;k < 4;k++){
            			int sx1 = sx;
            			int sy1 = sy;
            			int ex1 = ex;
            			int ey1 = ey;
            			if(sx + mx[k] >= 0 && sx + mx[k] < x
            					&& sy + my[k] >= 0 && sy + my[k] < y){
            				if(map[sy + my[k]][sx + mx[k]]){
            					sx1 = sx + mx[k];
            					sy1 = sy + my[k];
            				}
            			}
            			if(ex - mx[k] >= 0 && ex - mx[k] < x
            					&& ey - my[k] >= 0 && ey - my[k] < y){
            				if(map[ey - my[k]][ex - mx[k]]){
            					ex1 = ex - mx[k];
            					ey1 = ey - my[k];
            				}
            			}
            			String str = sx1+","+sy1+","+ex1+","+ey1;
            			if(ts.add(str)){
//            				System.out.println(str);
    						array.add(new Par(sx1,sy1));
    						array2.add(new Par(ex1,ey1));
    					}
            		}
    			}
    		}
    		return -1;
    	}
        void doIt() {
        	while(true){
        		int X = sc.nextInt();
        		int Y = sc.nextInt();
        		if(X+Y == 0)break;
        		array.add(new Par(sc.nextInt()-1,sc.nextInt()-1));
        		array2.add(new Par(sc.nextInt()-1,sc.nextInt()-1));
        		for(int i = 0;i < Y;i++){
        			for(int j = 0;j < X;j++){
        				map[i][j] = sc.nextInt() == 0 ? true:false ;
        			}
        		}
//        		for(int i = 0;i < Y;i++){
//        			for(int j = 0;j < X;j++){
//        				System.out.print(map[i][j]);
//        			}
//        			System.out.println();
//        		}
        		int num = roop(X,Y);
        		if(num == -1)System.out.println("NA");
        		else System.out.println(num);
        		array.clear();
        		array2.clear();
        		ts.clear();
        	}
    	}
    }
}

Measured memory_bytes: 220768