akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
// #define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=12,A=26;
string a[N];
string tmp[N];
int n,m;
int get(){
    int res=0;
    forn(i,n/2)
        forn(j,m)
            if(a[i][j]!=a[n-i-1][m-j-1])
                res++;
    if(n&1)forn(j,m/2)if(a[n/2][j]!=a[n/2][m-j-1])res++;
    return res;
}
void sr(int x,int y){
    a[x].swap(a[y]);
}
void sc(int x,int y){
    forn(i,n)swap(a[i][x],a[i][y]);
}
int otzhig(){
    uniform_real_distribution<> qqqqq(0,1);
    double t0=n+m;//2000
    double temp=t0;

    int cur=get();
    int ans=cur;

    uniform_int_distribution<> disrow(0,n-1);
    uniform_int_distribution<> discol(0,m-1);

    while(temp*max(n,m)>=1){//1e-6
        forn(i,n)tmp[i]=a[i];
        // dbg(temp,temp*10*(n+m),cur);
        forn(i,temp*n){
            int x=disrow(rng);
            int y=disrow(rng);
            sr(x,y);
        }
        forn(i,temp*m){
            int x=discol(rng);
            int y=discol(rng);
            sc(x,y);
        }

        int pot=get();
        upn(ans,pot);
        if(cur>pot)cur=pot;
        else{
            double go=exp(-(pot-cur)/temp);
            if(qqqqq(rng)<=go)cur=pot;
            else{
                forn(i,n)a[i]=tmp[i];
            }
        }
        temp*=0.9999;
    }
    // dbg(cx,cy,cur,temp);
    return ans;
}

int32_t main(){
    cin>>n>>m;
    forn(i,n)cin>>a[i];
    int ans=get();
    upn(ans,otzhig());
    upn(ans,otzhig());
    // upn(ans,otzhig());
    // upn(ans,otzhig());
    dbg(ans);
    if(ans)cout<<"NO\n";
    else cout<<"YES\n";

    return 0;
}

Measured memory_bytes: 4256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

template<typename Monoid,typename F>
struct SegmentTree{
	int sz;
	vector<Monoid> node;
	const F op;//演算
	const Monoid e;//単位元
	SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
		sz=1;
		while(sz<n) sz*=2;
		node.assign(2*sz,e);
	}
	void build(const vector<Monoid> &v){
		int n=v.size();
		for(int i=0;i<n;i++) node[i+sz-1]=v[i];
		for(int i=sz-2;i>=0;i--) node[i]=op(node[2*i+1],node[2*i+2]);
	}
	void update(int k,const Monoid &x){
		k+=sz-1;
		node[k]=x;
		while(k>0){
			k=(k-1)/2;
			node[k]=op(node[2*k+1],node[2*k+2]);
		}
	}
	Monoid query(int a,int b,int k=0,int l=0,int r=-1){
		if(r<0) r=sz;
		if(r<=a || b<=l) return e;
		if(a<=l && r<=b) return node[k];
		else{
			Monoid vl=query(a,b,2*k+1,l,(l+r)/2);
			Monoid vr=query(a,b,2*k+2,(l+r)/2,r);
			return op(vl,vr);
		}
	}
	Monoid operator[](const int &k)const{
		return node[k+sz-1];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,q;
	cin>>n>>q;
	auto op=[&](int a,int b){return min(a,b);};
	vector<int> a(n);
	rep(i,n) a[i]=(1ll<<31)-1;
	SegmentTree<int,decltype(op)> seg(n,op,(1ll<<31)-1);
	seg.build(a);
 	while(q--){
		 int c,x,y;
		 cin>>c>>x>>y;
		 if(c){
			 y++;
			cout<<seg.query(x,y)<<endl;
		 }else{
			 seg.update(x,y);
		 }
	}
}


Measured memory_bytes: 4040
while 1:
  n=int(input())
  if not n:break
  f=1
  L={}
  for a,b,c in [map(int,input().split()) for i in range(n)]:
    a=str(a)
    if a in L:
      if L[a]>=1e6:continue
      L[a]+=b*c
    else:L[a]=b*c
    if L[a] >= 1e6:print(a);f=0
  if f:print('NA')

Measured memory_bytes: 8320
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();

		int min = 1001;
		int max = -1;

		for (int i = 0; i < n; i++) {
			int tmp = sc.nextInt();
			if (tmp < min) {
				min = tmp;
			}
			if (tmp > max) {
				max = tmp;
			}
		}

		System.out.println(max - min);

		sc.close();
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
         
#define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
#define pb push_back
#define ll long long
#define ld long double
#define vll vector<ll>
#define infl LONG_LONG_MAX
#define infd LDBL_MAX
#define F first
#define S second
#define pll pair<ll,ll> 
#define G(a,b) get<a>(b)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define MT make_tuple
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fi(i,a,b) for(ll i=(b-1);i>=a;i--)    
#define endl "\n"
#define nl cout<<"\n";
#define pr(x) cout<<x;
#define pr1(x) cout<<x<<" ";
#define pr2(x,y) cout<<x<<" "<<y;
#define sz(x) (ll)x.size() 
#define ara cout<<"ara-ara\n"; 
const ld pi=3.141592653589793238;

inline ll ceil(ll a,ll b)
{
   return (a+b-1)/b;
}

const ll N=5e5+5;
ll arr[N],n,k;

bool can(ll x)
{
  ll res=0;
  f(i,1,n+1) 
  {
    if(arr[i]>x) res+=(ceil(arr[i],x)-1);
  }
  return res<=k;
}


void func()
{
  cin>>n>>k;
  f(i,1,n+1) cin>>arr[i];

  ll lef=1,rig=1e9+2,mid,ans=-1;
  while(lef<=rig)
  {
    mid=(lef+rig)>>1;
    if(can(mid)) ans=mid,rig=mid-1;
    else lef=mid+1;
  }

  cout<<ans<<"\n";

}   
     
     
     
int main() 
{
    fast
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif // ONLINE_JUDGE
     
    ll ntc=1;
    //cin>>ntc;
     
    f(i,1,ntc+1)
    {
       //cout<<"Case #"<<i<<": ";
       //cout<<"\n";
       func();
    }
     
    return 0;
}


Measured memory_bytes: 5124
s=input()
if s=="SAT":
	print(1)
elif s=="FRI":
	print(2)
elif s=="THU":
	print(3)
elif s=="WED":
	print(4)
elif s=="TUE":
	print(5)
elif s=="MON":
	print(6)
else:
	print(7)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int N; cin >> N;
  vector<int> A(N);
  for (auto& a : A) { cin >> a; --a; }
  map<pair<int, int>, int> m{};

  for (int i = 0; i < N; ++i) {
    m[{i, A[i]}] = 1;
  }

  ll cnt{};
  for (int i = 0; i < N; ++i) {
    if (m[{A[i], i}]) {
      ++cnt;
    }
  }
  auto ans = cnt / 2;
  cout << ans << CRLF;
  
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF LLONG_MAX
typedef pair<ll, ll> P;
P p[500001];
ll wa[500001];
int main(void){
	ll n;
	cin >> n;
	ll a, b;
	for(int i = 1; i <= n; i++){
		cin >> a >> b;
		p[i] = P(a, b);
	}
	sort(p + 1, p + n + 1);
	wa[0] = 0;
	for(int i = 1; i <= n; i++) wa[i] = wa[i - 1] + p[i].second;
	ll mx = -1, mn = INF;
	for(int i = 1; i <= n; i++){
		mn = min(mn, wa[i - 1] - p[i].first);
		mx = max(mx, wa[i] - p[i].first - mn);
	}
	cout << mx << endl;
	return 0;
}


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

int w[305], dp[305][305];

int main() {

    int n;
    while (cin >> n, n) {

        rep(i, n) cin >> w[i];
        rep(i, 305) rep(j, 305) dp[i][j] = 0;

        for (int ww=2; ww<=n; ++ww) {
            for (int i=0; i<n; ++i) {
                int j = i + ww - 1; // i - j ?????????
                if (j >= n) continue;

                if (dp[i+1][j-1] == ww-2 and abs(w[i] - w[j]) <= 1) dp[i][j] = ww;
                for (int k=i; k<j; ++k) {
                    dp[i][j] = max(dp[i][j], dp[i][k] + dp[k+1][j]);
                }
            }
        }

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

Measured memory_bytes: 3468
import java.util.Scanner;

public class Main {

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

	    int n=gi();

	    System.out.print(180*(n-2));
//	    if (S.contains("1") && S.contains("7") && S.contains("9") && S.contains("4")) {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35532
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = input()
rev = s[::-1]
ans = 0
for i in range(len(s)//2):
    if s[i] != rev[i]:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    char str[100];
    cin >> str;
    int n;
    for(n = 0; str[n] != 0; n++);
    n--;
    int count = 0;
    for(int i=0;(n%2) ? i<(n+1)/2 : i < n/2;i++){
        if(str[i] != str[n-i])  count++;
    }
    cout << count;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b,c;

main() {
    cin >> a >> b >> c;
    if (max(max(a,b),c)*2  == a+b+c) ct("Yes")
    else ct("No")
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int>sc[27];
int main(){
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		sc[s[i]-'a'].push_back(i);
	}
	int np = -1;
	ll ans = 0;
	for(int i=0;i<t.size();){
		if(sc[t[i]-'a'].size()==0)return 0*printf("-1\n");
		int pos = upper_bound(sc[t[i]-'a'].begin(),sc[t[i]-'a'].end(),np)-sc[t[i]-'a'].begin();
		if(pos==sc[t[i]-'a'].size()){
			np=-1;
			ans=ans+s.size();
		}
		else np=sc[t[i]-'a'][pos],i++;
	}
	printf("%lld\n",ans+np+1);
}

Measured memory_bytes: 1216
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s;
    s=sc.next();
    String d[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    for(int i=0;i<7;i++){
      if(d[i].equals(s)){
        System.out.println(7-i);
        break;
      }
    }
  }
}


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

using namespace std;

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    lint A[100000],B[100000],C[100000];
    for(int i=0;i<N;i++) cin >> A[i];
    for(int i=0;i<N;i++) cin >> B[i];
    for(int i=0;i<N;i++) cin >> C[i];
    
    sort(A,A+N);
    sort(B,B+N);
    sort(C,C+N);

    lint ans=0;
    for(int i=0;i<N;i++){
        ans+=distance(A,lower_bound(A,A+N,B[i]))*distance(upper_bound(C,C+N,B[i]),C+N);
    }

    cout << ans << endl;

    return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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 (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

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

    vector<ll> D(N),W(N);
    priority_queue<ll> TASHITEKU;
    vector<queue<ll>> ni(100000,queue<ll>());
    ll a,b;
    rep(i,N){
        cin >> a>>b;
        a--;
        ni.at(a).push(b);
    };
    
    ll ans=0;
    rep(i,M){
        while(!ni.at(i).empty()){
            TASHITEKU.push(ni.at(i).front());
            ni.at(i).pop();
        }
        if(!TASHITEKU.empty()){
            ans+=TASHITEKU.top();
            TASHITEKU.pop();
        }
    }
    cout << ans <<endl;
    return (0);
}

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

// debug
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef STOP_DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
template <typename T>
lint gcd(T a, T b) {return b?gcd(b, a%b):a;}

template <typename T>
lint lcm(T a, T b) {return a * b / gcd(a, b);};

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

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

struct IoSetup{
    IoSetup(){
      ios::sync_with_stdio(false);
      cin.tie(0);
      cout << fixed << setprecision(17);
      cerr << fixed << setprecision(17);
    }
} IoSetup;

int main() {
  string s, t; cin >> s >> t;
  cout << t << s << '\n';
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi f(n+1);
    for (int i=1; i*i<=n; ++i) {
        for (int j=1; j*j<=n; ++j) {
            for (int k=1; k*k<=n; ++k) {
                int val = i*i + j*j + k*k + i*j + j*k + k*i;
                if (val > n) continue;
                f[val]++;
            }
        }
    }
    rep1(i, n) cout << f[i] << endl;
    return 0;
}


Measured memory_bytes: 3588
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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















int main(){
    ll n;
    cin >> n;
    vector<ll> p(n), q(n);
    REP(i, n) cin >> p[i];
    REP(i, n) cin >> q[i];
    vector<ll> r(n);
    iota(r.begin(), r.end(), 1);
    ll a = -1, b = -1, c = 1;
    do{
        bool f1 = true;
        REP(i, n){
            if(r[i] != p[i]) f1 = false;
        }
        if(f1) a = c;
        bool f2 = true;
        REP(i, n){
            if(r[i] != q[i]) f2 = false;
        }
        if(f2) b = c;
        c++;
    }while(next_permutation(r.begin(), r.end()));
    cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
# This is a sample Python script.

# Press ⌃R to execute it or replace it with your code.
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press ⌘F8 to toggle the breakpoint.


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    n = int(input())
    arr = list(map(int, input().split()))
    arr = sorted(arr)  # 配列を昇順ソートしておく(配列に0がある場合0が先頭に来るので、場合分けの必要がなくなる)
    ans = 1
    for val in arr:
        ans *= val  # Pythonは多倍長整数をサポートしているので単に積を求めれば十分
        if ans > 10 ** 18:
            print(-1)
            break
    else:
        print(ans)

# See PyCharm help at https://www.jetbrains.com/help/pycharm/


Measured memory_bytes: 22624
#include "bits/stdc++.h"
using namespace std;
string s;
string month[]={"01","02","03","04","05","06","07","08","09","10","11","12"};
int main()
{
    cin>>s;
    string pre="",cur="";
    pre+=s[0];
    pre+=s[1];
    cur+=s[2];
    cur+=s[3];
    int cnt1=0,cnt2=0;
    for(int i=0;i<12;i++){
        if(pre==month[i]){
            cnt1=1; break;
        }
    }
    for(int i=0;i<12;i++){
        if(cur==month[i]){
            cnt2=1; break;
        }
    }
    if(cnt1&&cnt2){
        cout<<"AMBIGUOUS"<<endl;
    }else{
        if(cnt1){
            cout<<"MMYY"<<endl;
        }else if(cnt2){
            cout<<"YYMM"<<endl;
        }else{
            cout<<"NA"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    char t1, t2, t3;
    t1 = toupper(s1[0]);
    t2 = toupper(s2[0]);
    t3 = toupper(s3[0]);
    cout << t1 << t2 << t3;
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)

using ll = long long;
using Pii = pair<int, int>;

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

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

using MIte = multimap<ll, ll, greater<ll> >::iterator;

int S[200][200];

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

	// long long?
	ll N;
	cin >> N;

	vector<vector<int> > G(N);
	rep(i, N) {
		string str;
		cin >> str;
		rep(j, N) {
			S[i][j] = str[j] - '0';
			if (S[i][j] == 1) {
				G[i].push_back(j);
			}
		}
	}

	int maxK = 0;
	for (int m = 0; m != N; ++m) {
		vector<int> dist(N, -1);
		queue<int> que;

		dist[m] = 0;
		que.push(m);
		vector<vector<int> > vDist(N);
		while (!que.empty()) {
			int v = que.front();
			que.pop();

			for (int nv : G[v]) {
				if (dist[nv] != -1) continue;

				dist[nv] = dist[v] + 1;
				que.push(nv);
			}
		}
		int maxdist = 0;
		rep(i, N) {
			vDist[dist[i]].push_back(i);
			maxdist = max(maxdist, dist[i]);
		}
		bool connected = false;
		rep(i, N) {
			vector<int> v = vDist[i];
			for (int i = 0; i != v.size(); ++i) {
				for (int j = i; j != v.size(); ++j) {
					if (S[v[i]][v[j]] == 1) {
						connected = true;
						break;
					}
				}
			}
		}
		if (!connected) {
			maxK = max(maxK, maxdist);
		}
	}
	if (maxK == 0) {
		cout << "-1" << endl;
	}
	else {
		cout << maxK + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pr(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100100
#define MAX_N 100100
#define MAX_LOG_N 25
#define NIL -1
#define WHITE 0
#define BLACK 1
using namespace std;
typedef long long ll;
typedef map<ll, ll> Map;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;


int main(void) {
    ll N, K;
    cin >> N >> K;
    ll i;
    ll a[MAX];
    
    for(i=0; i<N; i++) {
        cin >> a[i];
    }
    
    ll ans=1+((N-K)+(K-2))/(K-1);
    pr(ans);
    
    
    
    
    
    
}








Measured memory_bytes: 1152
while 1:
    t = input()
    if t ==0: break
    card1 = []
    for i in range(t):
        card1 += [input()]
    t *= 2
    card1 = sorted(card1)
    card2 = range(1,t+1)
    for x in card1:
        card2.remove(x)
    ba = 0
    turn = 1
    while 1:
        if len(card1)==0 or len(card2)==0: break
        card = card1 if turn else card2
        cnt = 0
        while cnt < len(card):
            if card[cnt] > ba: break
            cnt+=1
        if cnt != len(card):
            ba = card.pop(cnt); turn = 1 - turn;
        else:
            ba = 0; turn = 1 - turn;
    print len(card2)
    print len(card1)

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

int main() {
  int d;
  cin >> d;
  string ans;
  if(d==25) ans = "Christmas";
  else if(d==24) ans = "Christmas Eve";
  else if(d==23) ans = "Christmas Eve Eve";
  else ans = "Christmas Eve Eve Eve";
  cout << ans << endl;
}


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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
// using ll = long long;
typedef long long ll;

bool check(vector<int> lst_w, ll p, int k) {
  int cnt = 0;
  ll sum_w = 0;
  rep(i, lst_w.size()) {
    sum_w += lst_w[i];
    if (sum_w > p) {
      cnt++;
      sum_w = lst_w[i];
    }
  }
  return cnt < k;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> lst_w(n, 0);

  int max_w = -1;
  rep(i, n) {
    cin >> lst_w[i];
    if (lst_w[i] > max_w) max_w = lst_w[i];
  }
  ll left = max_w, right = n * max_w / k + 1;

  ll ans;
  while (left <= right) {
    ll p = (left + right) / 2;
    if (check(lst_w, p, k)) {
      ans = p;
      right = p - 1;
    } else {
      left = p + 1;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;

namespace B042
{
	class Program
	{
		static void Main(string[] args)
		{
			List<int> n = Console.ReadLine().Split(' ').Select(int.Parse).ToList() ;
			n.Sort();

			if(n[0] == 5 && n[1] == 5 && n[2] == 7)
				Console.WriteLine("YES");
			else
				Console.WriteLine("NO");
		}
	}
}


Measured memory_bytes: 2776
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()

	ans := int64(math.Ceil((-1 + math.Sqrt(1+8*float64(N))) / 2))
	/*
	if N == 0 {
		ans = 1
	}
		ans2 := 0

		for i := 1; ; i++ {
			if i*(i+1) >= 2*N {
				ans2 = i
				break
			}
		}
	*/
	out(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>

typedef long long ll;

int bfs(std::vector<std::vector<int>> A)
{
    int H = A.size();
    int W = A[0].size();

    std::queue<ll> Q;
    // looking for start
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            if (A[i][j] == 0)
            {
                Q.push(i * W + j);
                // std::cout << i << " " << j << std::endl;
            }
        }
    }

    int l = 0;
    int maxcount = 0;
    while (true)
    {
        l++;
        ll v = Q.front();
        Q.pop();

        int i = v / W;
        int j = v % W;

        if (i != 0 && A[i - 1][j] == -1)
        {
            Q.push((i - 1) * W + j);
            A[i - 1][j] = A[i][j] + 1;
            maxcount = std::max(A[i - 1][j], maxcount);
        }

        if (i != H - 1 && A[i + 1][j] == -1)
        {
            Q.push((i + 1) * W + j);
            A[i + 1][j] = A[i][j] + 1;
            maxcount = std::max(A[i + 1][j], maxcount);

        }

        if (j != 0 && A[i][j - 1] == -1)
        {
            Q.push(i * W + (j - 1));
            A[i][j - 1] = A[i][j] + 1;
            maxcount = std::max(A[i][j - 1], maxcount);

        }

        if (j != W - 1 && A[i][j + 1] == -1)
        {
            Q.push(i * W + (j + 1));
            A[i][j + 1] = A[i][j] + 1;
            maxcount = std::max(A[i][j + 1], maxcount);

        }

        if (Q.empty())
            break;
        
    }

    return maxcount;
}

int main()
{
    int H, W;
    std::cin >> H;
    std::cin >> W;

    std::vector<std::vector<int>> A(H);
    for (int i = 0; i < H; i++)
    {
        A[i] = std::vector<int>(W);
        for (int j = 0; j < W; j++)
        {
            char c;
            std::cin >> c;
            if (c == '#')
                A[i][j] = 0;
            else
                A[i][j] = -1;
        }
    }

    std::cout << bfs(A) << std::endl;

    return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  queue<int> q;
  rep(i,m) {
    int a;cin>>a;q.push(a);
  }
  
  ll dp[n+1];
  dp[0]=1;
  if (q.front()==1) {
    dp[1]=0;q.pop();
  }
  else {
    dp[1]=1;
  }
  if (n>=2) {
    for (int i=2;i<n+1;i++) {
      if (i==q.front()) {
        dp[i]=0;q.pop();
      }
      else {
        dp[i]=dp[i-1]+dp[i-2];
        dp[i]%=1000000007;
      }
    }
  }
  cout<<dp[n]%(1000000007)<<endl;
}


Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(K: int, N: int, A: "List[int]"):
    print(K - max((A[i] - A[i - 1]) % K for i in range(N)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(K, N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26228
import sys
sys.setrecursionlimit(10**7)

N=int(input())
graph=[[] for _ in range(N)]

for _ in range(N-1):
    u,v,w=map(int,input().split())
    u-=1
    v-=1
    graph[u].append([v,w])
    graph[v].append([u,w])

color=[-1]*N
def even(v=0,col=0):
    color[v]=col
    for i in range(len(graph[v])):
        nv,nw=map(int,graph[v][i])
        if color[nv]!=-1: continue
        if nw%2==0:
            even(nv,col)
        else:
            even(nv,1-col)

even()
for i in range(N):
    print(color[i])


Measured memory_bytes: 99644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int n;
int A[100000];

int partition(int A[], int l, int r)
{
    int pivot = A[r];
    int lower = l - 1;
    for (int greater = l; greater < r; greater++) {
        if (A[greater] <= pivot) {
            lower++;
            swap(A[lower], A[greater]);
        }
    }
    swap(A[lower + 1], A[r]);
    return lower + 1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, n) { cin >> A[i]; }
    int idx = partition(A, 0, n - 1);
    rep(i, n)
    {
        if (i) {
            printf(" ");
        }
        if (i == idx) {
            printf("[");
        }
        printf("%d", A[i]);
        if (i == idx) {
            printf("]");
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3528
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int N,D;


int main(){
	cin>>N>>D;
	int ans=0;
	vector<vector<int>> X(N,vector<int>(D));


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

	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			float kyori = 0;
			for(int k=0;k<D;k++){
				kyori += (X.at(i).at(k)-X.at(j).at(k))*(X.at(i).at(k)-X.at(j).at(k));
			}
			kyori = sqrt(kyori);
			if(kyori == int(kyori))
				ans++;
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

#define debug(x) cout << #x << " : " << x << '\n';


// code //


int main() {
	ios::sync_with_stdio(false);

	int k; cin >> k;
	for(int i=0; i<k; ++i) cout << "ACL";
		
}	


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


vector<pair<int,int>> gra[100010];
ll dist[100010];

void dfs(ll x,ll y){
  for(const auto& it:gra[x]){
    ll s=it.first,len=it.second;
    if(dist[s]!=-1)continue;
    dist[s]=y+len;
    dfs(s,dist[s]);
  }
}

int main(){
  int n,q,k;cin >> n;
  rep(i,n-1){
    ll a,b,c;cin >> a>>b>>c;
    gra[a].push_back({b,c});
    gra[b].push_back({a,c});
  }
 
  cin >> q>>k;
   rep(i,100010)dist[i]=-1;
  dist[k]=0;
  
  dfs(k,0);
  rep(i,q){
    ll x,y;cin >> x>>y;
    ll ans=dist[x]+dist[y];
    cout << ans << endl;
  }
}
  


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

using namespace std;
using ll = long long;

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

  bool invalid = false;

  vector<ll> vec(n);
  cin >> vec[0];

  if (vec[0] != 0)
    invalid = true;

  for (int i = 1; i < n; i++)
  {
    cin >> vec[i];
    if (vec[i] > vec[i - 1] + 1)
      invalid = true;
  }

  if (invalid)
  {
    cout << -1 << endl;
    return 0;
  }

  ll cnt = 0;
  ll ans = vec[n - 1];
  for (int i = n - 2; i > 0; i--)
  {
    // 階段になっている場合は無視
    if (vec[i] == vec[i + 1] - 1)
    {
      continue;
    }
    // それ以外はその数値がコスト
    ans += vec[i];
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
int main(){
  int a,b,c;
  
  cin>>a>>b;
  vector<vector<char>> data(a+2, vector<char>(b+2,'#'));
  for (int i=1;i<=a;i++){
  	for (int j=1;j<=b;j++){
  		cin>>data.at(i).at(j);
  //    	cout<<data.at(i).at(j);
    }
  	cout<<endl;
  }
  
 // vector<vector<char>> data(a+2, vector<char>(b+2,'#'));
  for (int i=0;i<a+2;i++){
  	for (int j=0;j<b+2;j++){
      	cout<<data.at(i).at(j);
    }
  	cout<<endl;
  }
    //  vector<string> data(a);
//  for (int i=0;i<a;i++){
//    	cin>>data.at(i);
//  	  	cout<<data.at(i);
//    }
  	//cout<<endl;    
    
    
    
  

}

Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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



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

    int N;cin >> N;
    vector<long long> dams(N);
    for(int i = 0;i<N;i++) cin >> dams.at(i);
    long long sum = 0;
    for(int i = 0;i<N;i++) sum += dams.at(i);

    //山1に降った雨を考える
    long long mountain_1 = sum;
    for(int i = 1;i<N;i+=2){
        mountain_1 -= 2*dams.at(i);
    }
    cout << mountain_1 << " ";
    //山1を基に漸化式を解く
    //漸化式:mountain_i+1 = 2*dams_i - mountain_i
    long long mountain_i = mountain_1;
    for(int i = 1;i<N;i++){
        cout << 2*dams.at(i-1)-mountain_i << " ";
        mountain_i = 2*dams.at(i-1)-mountain_i;
    }
    cout << endl;
}


Measured memory_bytes: 3952
#B問題
N,A,B = map(int,input().split())
s = list(str(input()))
normal = 0
foreign = 0
for i in range(N):
    if s[i] == "a":
        if normal < A+B:
            normal+=1
            print("Yes")
        else:
            print("No")
    elif s[i] == "b":
        if normal < A+B and foreign < B:
            normal+=1
            foreign+=1
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4708
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <random>

using ll = long long;

//vector
template <class T>
using vec = std::vector<T>;

void solve()
{
    using namespace std;
    int W, a, b;
    cin >> W >> a >> b;
    
    if (a > b)
        swap(a, b);


    if (a + W < b)
        cout << b - (a + W) << endl;
    else
        cout << 0 << endl;


}

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

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

vector<long long> room[100000];
vector<long long> ans;
queue<long long> que;

int main() {
    long long N, M;
    cin >> N >> M;
    vector<pair<long long, long long>> AB(M);
    ans.resize(N + 1);
    rep(i, N + 1) { ans[i] = -1; }
    rep(i, M) { cin >> AB[i].first >> AB[i].second; }
    rep(i, M) {
        room[AB[i].first].push_back(AB[i].second);
        room[AB[i].second].push_back(AB[i].first);
    }

    ans[1] = 0;
    que.push(1);
    while (que.size() > 0) {
        long long r = que.front();
        for (vector<long long>::iterator iter = room[r].begin(); iter != room[r].end(); iter++) {
            if (ans[*iter] == -1) {
                ans[*iter] = r;
                que.push(*iter);
            }
        }
        que.pop();
    }
    for (long long i = 1; i < N + 1; i++) {
        if (ans[i] == -1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for (long long i = 2; i < N + 1; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 15856
//#include <stdio.h>
#include <bits/stdc++.h>
#include <climits>
using namespace std;
int main()
{   
    int n,m;
    int ans=0;
    bool flag=true;
    int count=0;
    cin >> n>>m;
    int state[m+1][n+2]={};
    int goal[m+1];
    for(int i=0;i<m;i++){
        cin >> state[i][0];
        for(int j=1;j<=state[i][0];j++){
            cin >>state[i][j];
        }
    }
    for(int i=0;i<m;i++){
        cin >> goal[i];
        //cout <<goal[i]<<endl;
    }
    for(int bit=0;bit<(1<<n);bit++){
        flag=true;
      //  cout<<"S";
        for(int i=0;i<m;i++){
            count=0;
            for(int j=1;j<=state[i][0];j++){
                if(bit&(1<<(state[i][j]-1))){
                    count++;
                }
            }
           // cout << count << "(" << (count % 2) << ")";
            if( (count % 2) != goal[i]){
                flag=false;
           //     cout<<"B";
            }
        }
        if(flag==true){
            ans++;
           /* cout <<bit <<" ";
            for(int a=0;a<n;a++){
                if(bit&(1<<a)){
                //    cout<<1;
                }else{
                  //  cout<<0;
                }
            }
           */
        }
      //  cout << endl;
    }
    cout << ans <<endl;
    }


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    LL n;
    cin>>n;
    VEC a(n+1);
    LL ans=0;
    for(LL i=1;i<=n;++i)cin>>a[i];
    for(LL i=1;i<=n;++i){
        if(a[i]==i){
            swap(a[i],a[i+1]);
            ans++;
        }
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a;
  cin >>a;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (a == i * j) {
        dout << i << "/" << j<<endl;
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

    void yes(bool fl = true){
            if(fl) cout << "YES\n";
            else cout << "Yes\n";
    }
    void no(bool fl = true){
        if(fl) cout << "NO\n";
        else cout << "No\n";
    }  

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;
        

        
        




        


        void solve(){
            cin >> n;
            ll cnt = 0;
            map<ll,ll> mp;
            for(int i=1;i<=n;i++){
                cin >> a;
                cnt += mp[i - a];
                mp[i+a]++;
            }
            cout << cnt << endl;
    
           
        }
    
   

        int main(){
        ios_base::sync_with_stdio(false);
       
        int cases = 1;
        //cin >> cases;

        while(cases--){ 
            solve();
        }

        return 0;

        }

Measured memory_bytes: 26252