akhauriyash/Code-Regression huggingface dataset:
/**
 * Created by hiramekun at 20:51 on 2019-09-01.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}


template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n;
    cin >> n;
    vl h(n);
    cin >> h;

    ll ans = 0;
    ll tmp = 0;
    for (ll i = 1; i < n; ++i) {
        if (h[i - 1] >= h[i]) tmp++;
        else tmp = 0;
        ans = max(tmp, ans);
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for( int i=0; i<N; i++ ){
    cin >> s.at(i);
  }
  
  int M;
  cin >> M;
  vector<string> t(M);
  for( int i=0; i<M; i++ ){
    cin >> t.at(i);
  }
  
  int X = 0;
  for( int i=0; i<N; i++ ){
    int tmp = 1;
    for( int j=i+1; j<N; j++ ){
      if( s.at(i) == s.at(j) ){
        tmp++;
      }
    }
    for( int j=0; j<M; j++ ){
      if( s.at(i) == t.at(j) ){
        tmp--;
      }
    }
    if( X < tmp ){
      X = tmp;
    }
  }
  
  cout << X << endl;
}


Measured memory_bytes: 3616
import java.util.*;
public class Main {

	public static void main(String[] args) {
		int MOD = 998244353;
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		long[][] dp = new long[C+1][D+1];
		long[][] S = new long[C+1][D+1];
		dp[A][B] = 1;
		for(int i = B; i < D; i++)
			dp[A][i+1] = dp[A][i] * A % MOD;
		for(int i = A; i < C; i++)
			dp[i+1][B] = dp[i][B] * B % MOD;
		for(int i = A+1; i <= C; i++)
			for(int j = B+1; j <= D; j++) {
				S[i][j] = (S[i-1][j] * (j-1) + dp[i-1][j]) % MOD;
				dp[i][j] = (dp[i][j-1] * i + S[i][j]) % MOD;
			}
		System.out.println(dp[C][D]);
	}

}

Measured memory_bytes: 178488
#include <bits/stdc++.h> 
 
using namespace std; 
 
 
 
int main() 
{
    string S;
	int Q;
    cin>>S;
  	cin>>Q;
 
  	bool order_flg=true;
  	for(int i=0;i<Q;i++){
      int Ti;
      cin>>Ti;
      if(Ti==1){
        if(order_flg==true)
  	      order_flg=false;
        else
          order_flg=true;
        }else{
        int Fi;
        char Ci;
        cin>>Fi>>Ci;
        if(Fi==1){
          if(order_flg==true)
            S.insert(S.begin(),Ci);
          else
            S.push_back(Ci);
        }
        else
          if(order_flg==true)
            S.push_back(Ci);
          else
            S.insert(S.begin(),Ci);
      }
   
    }
  	  if(order_flg==false)
        reverse(S.begin(),S.end());
  
      cout<<S<<endl;
 
  return 0;
}


Measured memory_bytes: 900
#include "bits/stdc++.h"
using namespace std;

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

	int N;
	cin >> N;

	vector<int> H(N);
	for (int i = 0; i < N; i++)
		cin >> H[i];

	for (int i = H.size() - 2; i >= 0; i--)
	{
		if (H[i] > H[i+1])
		{
			if (H[i] - H[i+1] > 1)
			{
				cout << "No\n";
				return 0;
			}
			else
				H[i]--;
		}
	}

	cout << "Yes\n";

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int max = (int)Math.pow(2,n) - 1;
			System.out.println("0:");
			for (int i = 1; i<=max; i++) {
				System.out.print(i+":");
				String binary = Integer.toBinaryString(i);
				for (int j=0; j<binary.length(); j++) {
					char c =  binary.charAt(binary.length()-j-1);
					if (c == '1') System.out.print(" "+ j);
				}
				System.out.print('\n');
			}
		}
	}
}


Measured memory_bytes: 68596
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    char str[50]={};
    int a,b;
    int i;
    int flage;
    while (scanf("%d%d",&a,&b)!=EOF)
    {
        scanf("%s",str);
        if (str[a]!='-')
        {
            printf("No\n");
            continue;
        }
        flage=0;
        for (i=0;i<a;i++)
        {
            if (str[i]<'0'||str[i]>'9')
            {
                flage=1;
                break;
            }
        }
        for (i=a+1;i<=a+b;i++)
        {
            if (str[i]<'0'||str[i]>'9')
            {
                flage=1;
                break;
            }
        }
        if (flage)
            printf("No\n");
        else
            printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 256
L = int(input())
C = list(map(int, input().split()))

cats = set()
cave = []

for i, c in enumerate(C, 1):
    if c > 0:
        if c not in cats:
            cats.add(c)
            cave.append(c)
        else:
            print(i)
            exit()
    else:
        c = abs(c)
        if len(cave) > 0 and cave[-1] == c:
            cats.remove(c)
            cave.pop(-1)
        else:
            print(i)
            exit()

print('OK')



Measured memory_bytes: 5616
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in();
	cout << (a > 0 ? "Positive" : b >= 0 ? "Zero" : (b - a + 1) % 2 == 0 ? "Positive" : "Negative") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n;
    cin>>n;
    ll t[n],a[n];
    for(int i=0;i<n;i++) cin>>t[i];
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=1;
    if(t[n-1]!=a[0]){
        cout<<0<<endl;
        return 0;
    }
    for(int i=1;i<n-1;i++){
        if(t[i]==t[i-1] && a[i]==a[i+1]){
            ans*=min(t[i],a[i]);
            ans%=MOD;
        }
        else if(t[i]>t[i-1] && a[i]==a[i+1] && a[i]<t[i]) ans=0;
        else if(t[i]==t[i-1] && a[i]>a[i+1] && a[i]>t[i]) ans=0;
        else if(t[i]>t[i-1] && a[i]>a[i+1] && a[i]!=t[i]) ans=0;
    }
    
    cout<<ans<<endl;
}

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

int main(){
	int N, M; cin >> N >> M;
	vector<int> X(M);

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

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

	vector<int> cul(M, 0);
	for(int i = 1; i < M; ++i){
		cul[i] = cul[i-1] + X[i] - X[i-1];
	}

	vector<int> s(M, 0);
	for(int i = 1; i < M; ++i){ s[i] = X[i] - X[i-1]; }
	sort(s.begin(), s.end(), greater<int>());

	int tsum = 0;
	for(int i = N-1; i < M; ++i) tsum += s[i];
	cout << tsum << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;cin>>N;
    int A[N],B[N],C[N];
    for(int i=0;i<N;i++){
        cin>>A[i]>>B[i]>>C[i];
    }int dpa[N],dpb[N],dpc[N];
    dpa[0]=A[0];dpb[0]=B[0];dpc[0]=C[0];
    for(int j=1;j<N;j++){
        dpa[j]=max(dpb[j-1],dpc[j-1])+A[j];
        dpb[j]=max(dpa[j-1],dpc[j-1])+B[j];
        dpc[j]=max(dpa[j-1],dpb[j-1])+C[j];
    }cout<<max(dpa[N-1],max(dpb[N-1],dpc[N-1]))<<endl;
}

Measured memory_bytes: 2560
// #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_4_B&lang=jp"

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

// #include "../../library/graph/topologicalsort.cpp"
// topologically sort the directed graph
// 0-indexed
struct TopologicalSort {
    int n;
    vector<set<int>> G;
    vector<bool> used;
    vector<int> indeg, p;

    TopologicalSort(int size) : n(size), G(n), used(n), indeg(n), p(0) {}

    void addEdge(int s, int t) { G[s].insert(t); }
    void bfs(int s) {
        queue<int> q;
        q.push(s);
        used[s] = 1;
        while (!q.empty()) {
            int v = q.front();
            q.pop();
            p.push_back(v);
            for (int u : G[v]) {
                indeg[u]--;
                if (indeg[u] == 0 && !used[u]) {
                    used[u] = 1;
                    q.push(u);
                }
            }
        }
    }
    // returns topologically sorted nodes
    // if p.size() < n, the graph cannot be sorted
    vector<int> build() {
        fill(used.begin(), used.end(), 0);
        fill(indeg.begin(), indeg.end(), 0);
        for (int i = 0; i < n; ++i) {
            for (int v : G[i])
                indeg[v]++;
        }
        for (int i = 0; i < n; ++i) {
            if (indeg[i] == 0 && !used[i])
                bfs(i);
        }
        return p;
    }
};

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    int v, e;
    cin >> v >> e;
    TopologicalSort graph(v);
    for (int i = 0; i < e; ++i) {
        int s, t;
        cin >> s >> t;
        graph.addEdge(s, t);
    }
    auto ret = graph.build();
    for (auto &r : ret) {
        cout << r << "\n";
    }
    cout << flush;
    return 0;
}


Measured memory_bytes: 5700
N = int(input())
ans = []
while N > 26:
    if N % 26 == 0:
        ans.append(26)
        N -= 26
    else:
        ans.append(N % 26)
    N //= 26
ans.append(N)
moji = ''
def num2alpha(num):
    if num<=26:
        return chr(64+num)
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(64+num%26)
for a in ans[::-1]:
    moji += num2alpha(a)
print(moji.lower())

Measured memory_bytes: 8968
#include "bits/stdc++.h"
#define REP(N) for(int i=0; i<N; i++)
using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;

    int* H = (int*)malloc(sizeof(int)*N);
    REP(N){cin >> H[i];}

    int minMtHeightNearestSea = 0;
    int ans = 0;
    REP(N)
    {
        if(H[i] >= minMtHeightNearestSea)
        {
            minMtHeightNearestSea = H[i];
            ans++;
        }
    }

    cout << ans << endl;

    free(H);
    return 0;
}


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

int main() {
  long long int x;
  cin >> x;
  long long int kane=100;
  for(long long int i=1;i<10000000;i++) {
    kane+=(kane/100);
    if(kane>=x) {
      cout << i << endl;
      break;
    }
    else {
    }
  }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Polygon | diff Polygon.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Polygon.cpp && ./a.out

/*
 
 2/10/2019
 
 18:09-
 
 */

const int MAX_N=1e6+1;
LL A[MAX_N];
int N;

void solve() {
  sort(A,A+N);
  LL a=A[N-1];
  LL b=accumulate(A,A+N-1,0LL);
  cout<<(a<b?"Yes":"No")<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  REP(i,N) cin>>A[i];
  solve();
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int min = Integer.MAX_VALUE;
    int max = Integer.MIN_VALUE;
    for (int i = 0; i < N; i++) {
      int a = sc.nextInt();
      min = Math.min(min, a);
      max = Math.max(max, a);
    }
    
    System.out.println(max - min);
  }
}

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

int main(void){
   string s;
   cin>>s;
   vector<char> ans;
   for(int i=0;i<s.size();i++){
      if(s[i]=='B'){
         if(ans.size()==0) continue;
         else ans.erase(ans.end()-1);
      }else{
         ans.push_back(s[i]);
      }
   }
   for(int i=0;i<ans.size();i++){
      cout<<ans[i];
   }
   return 0;
}



Measured memory_bytes: 256
a = list(input()[::-1])
b = list(input()[::-1])
c = list(input()[::-1])

now = a
while len(now):
  next_ = now.pop()
  if next_ == 'a':now=a
  elif next_ == 'b':now=b
  else:now=c
    
print(next_.upper())

Measured memory_bytes: 9116
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const int INF = 1000000007;

int N, A[100005];
multiset<int> st;

int main(void) {
  cin >> N;
  for(int i=0; i<N; i++) {
    int a; scanf("%d", &a);
    a *= -1;
    auto itr = st.upper_bound(a);
    if (itr != st.en) st.erase(itr);
    st.insert(a);
  }
  cout << st.size() << endl;
  
  
    
    return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = 0; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

bool swap(string &s, char a, char b, int j) {
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == a) {
      if (i < j)
        return false;
      s.at(i) = b;
    } else if (s.at(i) == b) {
      if (i < j)
        return false;
      s.at(i) = a;
    }
  }
  return true;
}

int main() {
  string s, t;
  cin >> s;
  cin >> t;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == t.at(i)) {
      continue;
    } else {
      bool flag = swap(s, s.at(i), t.at(i), i);
      if (!flag) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  if (s == t) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
    return 0;
  }
}


Measured memory_bytes: 776
#!/usr/bin/env python3

import numpy as np

def diff(pos1, pos2):
    return abs(pos1[0] - pos2[0]) + abs(pos1[1] - pos2[1])

H, W, D = map(int, input().split())
pos = dict()
for i in range(H):
    buf = list(map(int, input().split()))
    for j in range(W):
        pos[buf[j]] = (i, j)
        
Q = int(input())
query = []
for _ in range(Q):
    l, r = map(int, input().split())
    query.append((l, r))
        
cost = np.zeros(H * W + 1).astype(int)
for i in range(1, D + 1):
    cost[i] = 0
    x = i + D
    while x <= H * W:
        cost[x] = cost[x - D] + diff(pos[x - D], pos[x])
        x += D
        
for l, r in query:
    print(cost[r] - cost[l])
    

Measured memory_bytes: 52624
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long a, b, k;
  cin >> a >> b >> k;
  rep (i, k) {
    if (i % 2 == 0) {
      a /= 2;
      b += a;
    } else {
      b /= 2;
      a += b;
    }
  }
  cout << a << " " << b << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace _6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int kosuu = int.Parse(Console.ReadLine());
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Reverse(x);
            for (int i = 0; i < kosuu; i++)
            {
                if (!(i == 0))
                {
                    Console.Write(" ");
                }
                Console.Write(x[i]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9460
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] A = new int[n];
		int[] left = new int[n];
		int[] right = new int[n];
		for(int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}
		int ans = 0;
		left[0] = 0;
		for(int i = 1; i < n; i++) {
			left[i] = gcd(left[i-1], A[i-1]);
		}
		right[n-1] = 0;
		for(int i = n-2; i >= 0; i--) {
			right[i] = gcd(right[i+1], A[i+1]);
		}
		for(int i = 0; i < n; i++) {
			ans = Math.max(ans, gcd(left[i], right[i]));
		}
		//クラスにしないでL、Rをmain内に配列として入れるプランに変更
		
		System.out.println(ans);
		sc.close();
	}
	private static int gcd(int m, int n) {
	    if(m < n) return gcd(n, m);
	    if(n == 0) return m;
	    return gcd(n, m % n);
	}
	
}

Measured memory_bytes: 62720
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String aStr = sc.next();
		String bStr= sc.next();
		int a = 0;
		int b = 0;
		try {
			a = Integer.parseInt(aStr);
			b = Integer.parseInt(bStr);
			if (a >= 1 && b <= 100) {
				int area = a * b;
				int circ = 2 * a + 2 * b;
				System.out.println(area + " " + circ);
			}
		} catch (Exception e) {
			System.out.println("error");
		}
		sc.close();
	}
}

Measured memory_bytes: 25956
#include "bits/stdc++.h"

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-14
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int n,m,p,q,k,a,b,c,ans;
string s,str;
char ch;
vector<int> v;

dbl calcAngle(dbl h, dbl m)  
{  
    // validate the input  
    if (h <0 || m < 0 || h >12 || m > 60)  
        printf("Wrong input");  
  
    if (h == 12) h = 0;  
    if (m == 60) m = 0;  

    dbl hour_angle = 0.5 * (h * 60 + m);  
    dbl minute_angle = 6 * m;  
  
    dbl angle = abs(hour_angle - minute_angle);  
  
    angle = min(360 - angle, angle);  
  
    return angle;  
}  
 
dbl pi = 3.14159265358979323846;

void solve()
{
    dbl a,b;
    cin>>a>>b;
    int h,m;
    cin>>h>>m;

    dbl angle = calcAngle(h,m);
    dbl c = sq(a) + sq(b) - 2*a*b*cos(angle*pi/180);
    
    cout<<fixed<<setprecision(20)<<sqrt(c);
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 4188
import numpy as np
from collections import deque

n, m = map(int, input().split())
root = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    root[a - 1].append(b - 1)
    root[b - 1].append(a - 1)

ans = np.zeros(n, dtype = np.int)
ans[0] = 1
check = 0
queue = deque([0])

while queue:
    pos = queue.popleft()
    check += pos
    for next_pos in root[pos]:
        if ans[next_pos] != 0:
            continue
        ans[next_pos] = pos + 1
        queue.append(next_pos)
if check != n * (n - 1) / 2:
    print("No")
else:
    print("Yes")
    for i in range(1, n):
        print(ans[i])
        
        

Measured memory_bytes: 51588
#include <stdio.h>
#include <iostream>
#include <utility>
using namespace std;

int sort(int a[], int n);

int main(void)
{	
	int n, a[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	
	int num = sort(a, n);
	
	for (int i = 0; i < n; i++) {
		cout << a[i];
		if (i < n - 1) cout << " ";
		else cout << endl;
	}
	cout << num << endl;
	
	return 0;
}

int sort(int a[], int n)
{
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = n - 1; j > i; j--) {
			if (a[j] < a[j-1]) {
				swap(a[j], a[j-1]);
				cnt++;
			}
		}
	}
	
	return cnt;
}

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

int main()
{
	int a, b, c;

	cin >> a >> b >> c;

	a *= 100;
	b *= 10;

	if ((a + b + c) % 4 == 0)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;



Node treeSearch(Node u, int k){
  while(u != NIL){
    if(u->key > k) u = u->left;
    else if(u->key < k) u = u->right;
    else break;
  }
  return u;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x != NIL){
    y = x;
    if(z->key < x->key)  x = x->left;
    else x = x->right;
  }
  z->parent = y;
  if(y == NIL)  root = z;
  else if(z->key < y->key)  y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u == NULL) return ;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20440
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector> //*max_element(all(変数))で最大値を獲得
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  string s;  cin >> s;
  list<char> l;
  rep0(i,s.size()){
    if(s[i] == 'B'){
      if(!l.empty()) l.pop_back();
    }else{
      l.push_back(s[i]);
    }
  }
  for(auto x:l) cout << x;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n[10000];
int i=0;
int count=0;

while(1){
scanf("%d",&n[i]);
if(n[i] == 0) break;
i++;
count++;
}

for(i=0;i<count;i++){
printf("Case %d: %d\n",i+1,n[i]);
}
return 0;
}




Measured memory_bytes: 1924
import sys
N, T = map(int, sys.stdin.readline().strip().split())  # N個の帰宅経路, T時間以内に

cost = 1001
for line in sys.stdin.readlines():
    c, t = map(int, line.strip().split())
    if T >= t:
        cost = min(cost, c)

if cost == 1001:
    print('TLE')
else:
    print(cost)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == b && c != a) || (a == c && b != a) || (b == c && c != a)) {
		cout << "Yes";
		return 0;
	}
	cout << "No";
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

/*--------switch header--------*/
#define ALGORITHM   1
#define CASSERT     1
#define CMATH       1
#define DEQUE       1
#define FUNCTIONAL  1
#define IOMANIP     1
#define IOSTREAM    1
#define LIST        1
#define MAP         1
#define QUEUE       1
#define SET         1
#define STRING      1
#define UTILITY     1
#define VECTOR      1
#define VEC_DEBUG   1

using namespace std;

#pragma region headers
#if VEC_DEBUG
#define _GLIBCXX_DEBUG
#endif
#if ALGORITHM
#include <algorithm>
#endif
#if CASSERT
#include <cassert>
#endif
#if CMATH
#include <cmath>
#endif
#if DEQUE
#include <deque>
#endif
#if FUNCTIONAL
#include <functional>
#endif
#if IOMANIP
#include <iomanip>
#endif
#if IOSTREAM
#include <iostream>
#endif
#if LIST
#include <list>
#endif
#if MAP
#include <map>
#endif
#if QUEUE
#include <queue>
#endif
#if SET
#include <set>
#endif
#if STRING
#include <string>
#endif
#if UTILITY
#include <utility>
#endif
#if VECTOR
#include <vector>
#endif
#pragma endregion


/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define ALL(x)          (x).begin(), (x).end()
#define rALL(x)         (x).rbegin(), (x).rend()
#define REP(i, n)       for(int i = 0; (i) < (n); (i)++)
#define rREP(i, n)      for(int i = n - 1; (i) >= 0 ; (i)--)
#define FOR(i, a, b)    for(int i = (a); (i) < (b) ; (i)++)
#define CtoI(c)         int((c)) - int('0')

//functions=============
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };



/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    int ans[n+1];
    REP(i, n+1) ans[i] = 0;
    FOR(i, 1, 101)
    FOR(j, 1, 101)
    FOR(k, 1, 101){
        int s = i*i + j*j + k*k + i*j + j*k + k*i;
        if(s <= n) ans[s]++;
    }

    FOR(i, 1, n+1) cout << ans[i] << endl;

return 0;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

/*
使い方
Nとmodをセットする
*/

ll N = 1e6+1;
ll mod = 1e9 + 7;

ll fact[1000002];
ll invf[1000002];

ll f(ll a, ll x){
  ll res = 1;
  a %= mod;
  while(x > 0){
    if(x&1) res = res * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return res;
}

ll inv(ll x){
  return f(x, mod-2);
}

void gen_f(){
  fact[0] = invf[0] = 1;
  FOR(i,1,N){
    fact[i] = i * fact[i-1] % mod;
    invf[i] = inv(fact[i]);
  }
}

ll P(ll n, ll r){
  return fact[n] * invf[n-r] % mod;
}

ll C(ll n, ll r){
  return P(n, r) * invf[r] % mod;
}

int h,w;
int a,b;


int main(){
  cin >> h>>w>>a>>b;
  gen_f();
  ll sum=0;
  FOR(i,b,w){
    ll k1 = C(i+h-a-1,i);
    ll k2 = C(a-1+w-i-1,a-1);
    sum += k1*k2 % mod;
    sum %= mod;
  }
  cout << sum << endl;
}


Measured memory_bytes: 15872
#include<stdio.h>
int main(void)
{
	int i,n,T=1;
	scanf("%d",&n);

	char s[n+1];
	scanf("%s",s);
	for(i=1;i<n;i++){
		if(s[i-1]!=s[i])
			T++;
	}
		printf("%d\n",T);
		
		return 0;

}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& e : a) cin >> e;
  sort(a.begin(), a.end());

  int r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] == a[j]) continue;
      for (int k = j + 1; k < n; k++) {
        if (a[i] == a[k]) continue;
        if (a[j] == a[k]) continue;
        if (a[i] + a[j] > a[k]) r++;
      }
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
signed main(){
    int a,b;
  cin>>a>>b;
  vector<int> c(b),d(b);
  rep(i,b)
    cin>>c[i]>>d[i];
  int dp[1010][20020];
  rep(i,1010)rep(j,20020)
    dp[i][j]=INF;
  rep(i,b)
    dp[i][0]=0;
  rep(i,b)rep2(j,a+10010){
    chmin(dp[i+1][j],dp[i][j]);
  if(j>=c[i])
    dp[i+1][j]=min(dp[i+1][j],dp[i+1][j-c[i]]+d[i]);
  }
  int ans=INF;
  rep(i,20020-a){
  chmin(ans,dp[b][a+i]);
    }
  cout<<ans<<endl;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  int a,b,c,d,e;
  string s,ss;
  cin>>a>>b>>c;
  cout<<(a-b+1)*(a-c+1)<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


n = 60
N = read_a_int()
A = read_ints()


def ret_binary(a: int):  # 逆順で返すことに注意
    ret_r = [0] * n
    for i in range(n):
        bit = a % 2
        a = a // 2
        ret_r[i] = bit
    return ret_r


MOD = 10**9 + 7

n_1_max = 0
n_1_ls = [0] * n
ans = 0
for a in A:
    tmp = ret_binary(a)
    for i in range(n):
        n_1_ls[i] += tmp[i]


for i, n_1 in enumerate(n_1_ls):
    num_sonoketa = n_1 * (N - n_1)
    ans += (((2**i) % MOD) * num_sonoketa)
    ans %= MOD
print(ans)


Measured memory_bytes: 123084
def main():
  n = int(input())
  p = list(map(int, input().split(' ')))
  c = 0
  for i in range(n):
    c += 0 if i+1 == p[i] else 1
  print('YES' if c <= 2 else 'NO')


if __name__ == '__main__':
  main()

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

int main() {
  int a;
  string s;
  cin >> a >> s;
  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(){
int i, x;
scanf("%d", &x);
for ( i =1; i < x +1; i++ ){
if ( i % 3 == 0  )
printf(" %d", i);
else if ( i % 10 == 3 )
printf(" %d", i);
else if ( 30 <= i % 100 && i % 100 <= 39 )
printf(" %d", i);
else if ( 300 <= i % 1000 && i % 1000 <= 399)
printf(" %d", i);
else if( 3000 <= i && i <= 3999)
printf(" %d", i);
if ( i == x )
printf("\n");
}
return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int A,B;
  cin >> A >> B;
  int a = A+B;
  int b = A-B;
  int c = A*B;
  int ans = max(max(a,b),c);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    int X,Y;
    cin >> X >> Y;
    int ans = max(100000*(4-X), 0) + max(100000*(4-Y), 0);
    if(X == 1 && Y == 1) {
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
  int e;
  while (cin >> e) {
    if (!e) { break; }
    int ans = e;
    for (int z = 0; z <= 101; z++) {
      for (int y = 0; y <= 1001; y++) {
        int x = e - y*y - z*z*z;
        if (0 <= x && x <= 100000) {
          ans = min(ans, x+y+z);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}



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

#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll ;
typedef long double ld ;

const ll MOD = 998244353 ;
const double PI = 2 * acos(0.0) ;
const long double EPS = 1.0E-14 ;

int arr[100005], dp[100005] ;
int ans = 1e8 ;

int check(int pos)
{
    if (dp[pos] != -1) {
        return dp[pos] ;
    }
    else {
        if (pos - 2 >= 0) return dp[pos] = ( min(check(pos - 1) + abs(arr[pos] - arr[pos - 1]), check(pos - 2) + abs(arr[pos] - arr[pos - 2])) )  ;
        else if (pos - 1 >= 0) return  dp[pos] = ( check(pos - 1) + abs(arr[pos] - arr[pos - 1]) ) ;
    }
}

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

    for (int i = 0; i < n; i++) {
        cin >> arr[i] ;
        dp[i] = -1 ;
    }
    dp[0] = 0 ;
    ans = check(n - 1) ;
    cout << ans ;

    return 0 ;
}


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

int p2(int n){
	int ret=1;
     while(n--){
     ret*=2;
     } 
  	return ret;
}

signed main(){
	int n,p;cin>>n>>p;
  	int odd=0;
  	for(int i=0;i<n;i++){
    	int x;cin>>x;
      	if(x%2==1)odd++;
    }
  if(odd>0)cout<<p2(n-1)<<endl;
  else if(p==0)cout<<p2(n)<<endl;
  else cout<<0<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, (b), sizeof(a))
#define fore(i,a) for(int i=0;i<a;i++)
#define fore1(i,j,a) for(int i=j;i<a;i++)
#define print(ar) for(int i=0;i<ar.size();i++)cout<<ar[i]<<" ";
#define END cout<<'\n'
const double pi=acos(-1.0);
 
typedef pair<int, int> PII;
 
typedef vector<int> VI;
 
typedef vector<string> VS;
 
typedef vector<PII> VII;
 
typedef vector<VI> VVI;
 
typedef map<int,int> MPII;
 
typedef set<int> SETI;
 
typedef multiset<int> MSETI;
 
typedef long int li;
 
typedef unsigned long int uli;
 
typedef long long int ll;
 
typedef unsigned long long int  ull;
ll fastexp (ll a, ll b, ll n) {
  ll res = 1;
  while (b) {
      if (b & 1) res = res*a%n;
      a = a*a%n;
      b >>= 1;
  }
  return res;
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}

int main()
 {  fast();
    int x,n;
    cin>>x>>n;
   
    VI vec(n);
    int ans=x;
    int ind=-1;
    fore(i,n){
        cin>>vec[i];
       // if(vec[i]==x)ind=i;
    }
        
    sort(vec.begin(),vec.end());
     fore(i,n){
    
        if(vec[i]==x)ind=i;
    }
    if(ind==-1)ans=x;
    else{
        int temp1=x;
        int temp2=x;
        for(int i=ind;i>=0;i--){
            if(vec[i]==temp1){
                temp1--;
            }else {
                break;
            }
        }
          for(int i=ind;i<n;i++){
            if(vec[i]==temp2){
                temp2++;
            }else {
                break;
            }
        }
       // cout<<temp1<<" "<<temp2<<endl;
        if(abs(temp1-x)<=abs(temp2-x))ans=temp1;
        else ans=temp2;
       
    }
    cout<<ans<<endl;
 }


Measured memory_bytes: 3652
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, -1, mod)


def main():
    n = int(input())
    a = list(map(int, input().split()))
    c = [0] * (n+1)
    for i in range(n):
        c[i+1] = c[i] + a[i]

    ans = 0
    for i in range(n):
        ans += a[i] * (c[n] - c[i+1])
        ans %= mod
    print(ans)
main()


Measured memory_bytes: 94976
function Main(input){
    input = input.split("\n");
    var k = 0;
    while(1){
        var n = parseInt(input[k++],10);

        if(n == 0)
            break;
        input[k] = input[k].split(" ");

        var ans = 0;
        for(var i = 0;i < Math.floor(n / 2);i++){
            if(input[k][i * 2][1] == input[k][i * 2 + 1][1])
                ans++;
        }
        console.log(ans);
        k++;
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 17300
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1e9;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

struct Edge
{
	int to, c;
	Edge(){}
	Edge(int to, int c) : to(to), c(c) {};
};

vector<Edge> es[110];
int d[110][2];
bool used[110];

void dijkstra(){
	d[0][1] = d[0][0] = 0;
	used[0] = true;
	set<pair<int, pii> > st;
	st.insert(mp(0, mp(0, 1)));
	st.insert(mp(0, mp(0, 0)));
	pair<int, pii> p;
	while(!st.empty()){
		p = *st.begin(); st.erase(st.begin());
		int from = p.se.fi, f = p.se.se, c = d[from][f];
		for(int i = 0; i < es[from].size(); i++){
			int to = es[from][i].to, cost = c + es[from][i].c;
			if(d[to][f] > cost) {
				d[to][f] = cost;
				st.insert(mp(cost, mp(to, f)));
			}
			if(f == 1){
				for(int j = 0; j < es[to].size(); j++){
					int to2 = es[to][j].to;
					if(d[to2][0] > c){
						d[to2][0] = c;
						st.insert(mp(c, mp(to2, 0)));
					}
				}
			}
		}
		used[from] = true;
	}
}

int main(){
	while(1){
		int n = in.nextInt(), m = in.nextInt();
		if(n == 0 && m == 0) break;
		rep(i, 110) es[i].clear();
		rep(i, 110) rep(j, 2) d[i][j] = INF;
		rep(i, 110) used[i] = false;
		rep(i, m){
			int a = in.nextInt() - 1, b = in.nextInt() - 1, c = in.nextInt();
			es[a].pb(Edge(b, c));
			es[b].pb(Edge(a, c));
		}

		dijkstra();

		printf("%d\n", min(d[n - 1][1], d[n - 1][0]));
	}
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int N;
    long count2 = 1;
    string S;
    cin >> N >> S;
    vector<int> vec(30);
    sort(S.begin(),S.end());
    int a = 0;
    for(int i = 0;i < N;i++){
        if(i == 0){
            vec.at(a)++;
        }else if(S.at(i) == S.at(i - 1)){
            vec.at(a)++;
        }else{
            a++;
            vec.at(a)++;
        }
    }
    for(int i = 0;i < vec.size();i++) {
        count2 *= (vec.at(i)+1);
        count2 %= 1000000007;
    }
    cout << (count2 - 1) << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll g = a[0];
  rep(i, n) g = __gcd(g, a[i]);
  int ans = 0;
  while(g%2 == 0) {
    ++ans;
    g /= 2;
  }
  cout << ans << endl;
}



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

#define fi first
#define se second
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for (int i = a; i <= (b); i++)
#define ROF(i, a, b) for (int i = a; i >= (b); i--)

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n; cin >> n;
    int lst; cin >> lst;
    ll ans = 0;
    FOR(i, 1, n - 1) {
        int cur; cin >> cur;
        if (cur < lst) ans += lst - cur;
        else lst = cur;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3576
import java.util.Scanner;

//Square Route
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m)==0)break;
			int[] h = new int[n];
			for(int i=0;i<n;i++)h[i]=sc.nextInt();
			int[] w = new int[m];
			for(int i=0;i<m;i++)w[i]=sc.nextInt();
			int[] wh = new int[1500001];
			int[] ww = new int[1500001];
			for(int i=0;i<n;i++){
				int s = 0;
				for(int j=i;j<n;j++){
					s+=h[j];
					wh[s]++;
//					System.out.println("WH i:" + i + " j:" + j);
				}
			}
//			for(int i=1;i<=20;i++)System.out.println("H: Wid:" + i + " NUM: " + wh[i]);
			for(int i=0;i<m;i++){
				int s = 0;
				for(int j=i;j<m;j++){
					s+=w[j];
					ww[s]++;
//					System.out.println("WW i:" + i + " j:" + j);
				}
			}
//			for(int i=1;i<=20;i++)System.out.println("W: Wid:" + i + " NUM: " + ww[i]);
			int c = 0;
			for(int i=0;i<1500001;i++)c+=wh[i]*ww[i];
			System.out.println(c);
		}
	}
}

Measured memory_bytes: 24000