akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
struct UnionFind {
  vector<ll> data;
  ll num;
  UnionFind(ll size) : data(size, -1) ,num(size){ }
  bool unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
	  num--;
    }
    return x != y;
  }
  bool find(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,k,l;cin>>n>>k>>l;
  UnionFind uf1(n),uf2(n);
  rep(i,0,k){
    ll p,q;cin>>p>>q;p--;q--;
    uf1.unite(p,q);
  }
  rep(i,0,l){
    ll r,s;cin>>r>>s;r--;s--;
    uf2.unite(r,s);
  }
  map<P,ll>mp;
  rep(i,0,n){
    mp[MP(uf1.root(i),uf2.root(i))]++;
  }
  vector<ll>ret(n);
  rep(i,0,n)ret[i]=mp[MP(uf1.root(i),uf2.root(i))];
  debug(ret,n);
  return 0;
}

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

#define endl "\n"
#define int long long int
#define mod 1000000007
#define vi vector<int>
#define pint pair<int,int>
#define vint vector<vector<int>>
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

const int N = 1e6+5;
int A[N], B[N], P[N], ans[N];

int mat[1005][1005];
pint edges[N];
unordered_map<int, set<int>> m;

bool compare(vi a, vi b)
{
    return a[0] < b[0];
}

int mypow(int a, int x)
{
    if(a<=1 || x==1) return a;
    if(x==0) return 1;

    int temp = mypow(a,x/2);
    if(x%2==0) return ((temp%mod) * (temp%mod))%mod;
    else return (a%mod * ((temp%mod) * (temp%mod))%mod)%mod;
}

int count_bits(int n)
{
    int cnt = 0;
    while(n)
    {
        n = n & (n-1);
        cnt++;
    }return cnt;
}

void bfs(int src, int n)
{
    unordered_map<int, bool> visited;
    for(int i=0;i<n;i++) visited[i] = false;
    queue<int> q;
    q.push(src);
    visited[src] = true;

    while(!q.empty())
    {
        int curr = q.front();
        q.pop();
        B[curr] -= min(B[curr], A[src]);
        //cout<<curr<<" "<<endl;

        for(auto neigh: m[curr])
        {
            if(visited[neigh] == false)
            {
                //cout<<neigh<<endl;
                q.push(neigh);
                visited[neigh] = true;
                m[src].erase(neigh);
                m[neigh].erase(src);
            }
        }
    }
}

/*void void_solve(int n)
{

}*/

int int_solve(int n, int x, int t)
{
    int ans = 0;
    if(n%x == 0) ans = n/x;
    else ans = n/x + 1;
    ans *= t;
    return ans;
}

/*string string_solve(int n)
{

}*/

/*bool bool_solve(int n)
{
    int i;
    if(n == 1) return true;
    if(is_sorted(A, A+n)) return true;

    for(i=0;i<n;i++) B[i] = A[i];
    sort(B, B+n);

    int minimum = *min_element(A, A+n);
    for(i=0;i<n;i++)
    {
        if((B[i] % minimum) != 0)
        {
            if(A[i] != B[i]) return false;
        }
    }return true;
}*/

int32_t main()
{
    //code
	IOS;

    int t,n,m,a,b,x,y,i,j,z;
    //cin>>t;
    cin>>n>>x>>t;
    cout<<int_solve(n,x,t)<<endl;

	return 0;
}


Measured memory_bytes: 3612
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var bellmanFord = (function(){
  var INF = 1e9;
  function f(graph,start){
    return new bellmanFord(graph,start);
  }
  function bellmanFord(graph,start){
    var n = graph.length, n2 = n << 1;
    var dist = this.d = Array(n).fill(INF);
    dist[start] = 0;
    for(var i = 0; i < n2; i++){
      for(var v = 0; v < n; v++){
        for(var k = 0; k < graph[v].length; k++){
          var e = graph[v][k];
          if(dist[v] !== INF && dist[e.to] > dist[v] + e.cost){
            if(i >= n-1)dist[e.to] = -INF;
            else dist[e.to] = dist[v] + e.cost;
          }
        }
      }
    }
  }
  bellmanFord.prototype.dist = function(i){
    return this.d[i];
  };
  return f;
})();

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var p = o.a();
  var graph = xArray("[]",n);
  for(var i = 0; i < m; i++){
    var t = o.l(), a = t[0]-1, b = t[1]-1, c = t[2];
    graph[a].push({to:b,cost:p-c});
  }
  var bf = bellmanFord(graph,0);
  if(bf.dist(n-1) === -1e9)return -1;
  if(bf.dist(n-1) >= 0)return 0;
  return -bf.dist(n-1);
}

Measured memory_bytes: 10640
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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;
}
template <class T>
ostream &operator<<(ostream &out, vector<T> const &v) {
    for (auto &&a : v) out << a << " ";
    out << endl;
    return out;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N;
    cin >> N;
    int r = 0;
    REP(i, 1000000000) {
        r += i;
        if (r >= N) {
            cout << i;
            return;
        }
    }
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3660
from copy import copy, deepcopy
from collections import Counter
from math import sqrt, floor, factorial
from itertools import permutations, combinations, combinations_with_replacement
from operator import mul
from functools import reduce

MOD = 10**9 + 7
INF = float('inf')

X = int(input())
flag = 0
if X == 0:
    print("0 0")
    exit()

for i in range(1, int(1 + sqrt(X))):
    if flag == 1:
        exit()
    elif X % i == 0:
        B = 0
        while B**4 < X+1 and flag == 0:
            if ((B+i)**5 - B**5 == X) or (((-1*B+i)**5 + B**5 == X)):
                if ((B+i)**5 - B**5 == X):
                    print("{} {}".format(B+i, B))
                    flag = 1
                else:
                    print("{} {}".format(-1*B+i, -1*B))
                    flag = 1
            B += 1


Measured memory_bytes: 9736
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char maps[7][7];
int sum;
int ans;
int a[7];
int b[7];

int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            cin>>maps[i][j];
            if(maps[i][j]=='#')
            {
                sum++;
                a[i]++;
                b[j]++;
            }
        }
    }
    for(int i = 0; i < (1<<n); i++)
    {
        for(int x = 0; x < (1<<m); x++)
        {
            int t=sum;
            for(int j = 0; j < n; j++)
            {

                if(i & (1 << j))
                {
                    t=t-a[j];
                }
            }
            for(int y = 0; y < m; y++)
            {
                if(x & (1 << y))
                {
                    t=t-b[y];
                }
            }
            for(int j = 0; j < n; j++)
            {
                for(int y = 0; y < m; y++)
                {
                    if(i & (1 << j)&&x & (1 << y))
                    {
                        if(maps[j][y]=='#')
                        {
                            t++;
                        }
                    }
                }
            }
            if(t==k)
            {
                ans++;
            }

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int> X(5);
    for (int i=0;i<5;i++) {
        cin >> X.at(i);
        if(X.at(i)==0) {
            cout << i+1 <<endl;
        }
    }
    
    

}

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

namespace AOJ_ICPC1 {
	struct Pair {
		public int sa, sb;
		public Pair(int _sa, int _sb) {
			sa = _sa; sb = _sb;
		}
	}
	class Program {
		static void Main(string[] args) {

			while (true) {
				string[] str1 = Console.ReadLine().Split(' ');
				int n = int.Parse(str1[0]);
				int m = int.Parse(str1[1]);
				if (n == 0 && m == 0) break;
				int[] sa = new int[n];
				int[] sb = new int[m];
				for (int i = 0; i < sa.Length; i++) sa[i] = int.Parse(Console.ReadLine());
				for (int i = 0; i < sb.Length; i++) sb[i] = int.Parse(Console.ReadLine());

				int[] answer = result(sa, sb);
				if (answer!=null) Console.WriteLine("{0} {1}", answer[0], answer[1]);
				else Console.WriteLine("-1");
			}
		}

		static int[] result(int[] sa, int[] sb) {
			int suma = sa.Sum();
			int sumb = sb.Sum();
			List<Pair> ans = new List<Pair>();
			for (int a = 0; a < sa.Length; a++) {
				for (int b = 0; b < sb.Length; b++) {
					if (suma + 2 * sb[b] == sumb + 2 * sa[a]) ans.Add(new Pair(sa[a], sb[b]));
				}
			}
			if (ans.Count == 0) return null;
			ans.Sort((t1, t2) => t1.sa + t1.sb - t2.sa - t2.sb);
			return new int[] { ans.First().sa, ans.First().sb };
		}
	}
}

Measured memory_bytes: 6216
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
  int n;
  cin >> n;
  if(n%2 == 0) cout << 0.50000000 << endl;
  else cout << (double)(n/2+1)/(double)n << endl;

  
  return 0;

}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    ll count = 0;
    vector<ll> A;
    cin >> N;
    A.resize(N);
    rep(i, N) {
        ll temp;
        cin >> A[i];
        temp = A[A[i] - 1];
        if(temp != 0 && temp == i + 1) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
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;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int ary[n];
    rep(i,n) cin >> ary[i];

    double ans = 0;
    rep(i,n)
    {
        ans += (double)1.0/ary[i];
    }
    cout << fixed << setprecision(10) << (double) 1.0/ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define MOD 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> pii;
typedef pair<double, double> dop;
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 gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    int x, a;
    cin >> x >> a;
    int out = (x < a) ? 0 : 10;
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
from bisect import bisect_left
from collections import deque

n = int(input())
a = [int(stdin.readline()) for _ in range(n)]

l = deque()

for i in range(n):
  n = bisect_left(l, a[i])
  if n == 0:
    l.appendleft(a[i])
  else:
    l[n - 1] = a[i]

print(len(l))




Measured memory_bytes: 8060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a;i<n;i++)
#define ve vector
#define ss second 
#define ff first
#define pf pop_front
#define pob pop_back
#define psf push_front
#define res(x) cout<<x<<'\n'
#define read(t) ll t;cin>>t

int main(){
   ll k,n;
   cin>>k>>n;
   ll a[n];
   f(i,0,n){
       cin>>a[i];
   }
   sort(a,a+n);
   ll ans=0;
   ll maxm=0;
   f(i,0,n-1){
       if(a[i+1]-a[i]>=maxm){
           maxm=a[i+1]-a[i];
          
       }
        ans+=a[i+1]-a[i];
      
   }
    ll temp=k-a[n-1]+a[0];
    if(temp>maxm){
        cout<<ans<<endl;
    }
    else{
        cout<<ans-maxm+temp<<endl;
    }
}

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

int n;
bool found = false;
int main(){
    cin >> n;
    for(int i = 1; i <= 9; i++){
        if(n % i == 0 && n/i >= 1 && n/i <= 9) found = true;
    }
    cout << (found ? "Yes" : "No");
}


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

int main(){
   int h,w,m;
   cin >> h >> w >> m;
   vector<int> b_h(m), b_w(m);
   set<pair<int,int>> s;
   map<int, int> m_h,m_w;
   for(int i=0; i<m; i++){
       int a,b;
       cin >> a >> b;
       b_h.at(i)=a;
       b_w.at(i)=b;
       m_h[a]++;
       m_w[b]++;
       pair<int, int> pa = make_pair(a,b);
       s.insert(pa);
   }
   int p=0,q=0;
   for(auto k:m_h){
       p=max(p,k.second);
   }
   for(auto k:m_w){
       q=max(q,k.second);
   }
   vector<int> max_h,max_w;
   for(auto k:m_h){
       if(k.second == p) max_h.push_back(k.first);
   }
   for(auto k:m_w){
       if(k.second == q) max_w.push_back(k.first);
   }
   for(int i=0; i<max_h.size(); i++){
       for(int j=0; j<max_w.size(); j++){
           int ans_h,ans_w;
           ans_h = max_h.at(i);
           ans_w = max_w.at(j);
           pair<int, int> check = make_pair(ans_h,ans_w);
           if(!s.count(check)){
               cout << p+q  << endl;
               return 0;
           }
       }
   }
   cout << p+q-1 << endl;
}

Measured memory_bytes: 51900
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

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

    ll count = 0, flag = 0;
    rep(0, i, N)
    {
        ll d1, d2;
        cin >> d1 >> d2;
        if (d1 == d2)
        {
            count++;
        }
        else
        {
            count = 0;
        }

        if (count == 3)
        {
            flag = 1;
        }
    }

    if (flag == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3616
// It’s always great to set new goals, keep trying, keep training, and then achieve those goals.
#include <bits/stdc++.h>
#define ll long long int
#define f(i,n) for(ll i=0;i<n;i++)
#define rf(i,n) for(ll i=n;i>=0;i--)
#define endl '\n'
#define pub push_back
#define vf v[i].first
#define vs v[i].second
#define mp make_pair
#define z 998244353   
using namespace std;
ll powMod(ll x,ll y){ll p=1; while(y){if(y%2){p=(p*x)%z;} y/=2; x=(x*x)%z;} return p;}
ll invMod(ll x){return powMod(x,z-2);}
ll gcd(ll a, ll b) {return b == 0 ? a : gcd(b, a % b);}

const int N = (int)2e5 + 100;
set<char> st[N];
ll visited[N];

void solve(){ 
    ll n;
    cin>>n;
    ll a[n];
    ll dp[n];
    f(i,n)cin>>a[i];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);
    for(ll i=2 ;i<n ;i++){
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<dp[n-1]<<endl;
}
int main(){
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ; cout.tie(0) ;

    solve();
   
    return 0;
}

Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define mod 1000000009
typedef long long ll;
using namespace std;

const int MAX = 100005;
const int INF = 1000000000;
int dp[MAX];
int h[MAX];
int n,k;

int main(){
  cin >> n >> k;
  for(int i=0;i<n;i++) cin >> h[i+1];
  for(int i=1;i<=n;i++) dp[i] = INF;
  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);

  for(int i=3;i<=n;i++){
    for(int j=1;i-j>=1 && j<=k;j++){
      dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
    }
  }

  cout << dp[n] << endl;
  return 0;
}


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

using namespace std;
#define ll long long

ll const lmt = 2e5+6;


int main(){
  int maxx, miny;
  int n,m;
  cin >> n >> m >> maxx >> miny;
  
  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    if(tmp > maxx){
      maxx = tmp;
    }
  }
  
  for(int i = 0; i < m; i++){
    int tmp;
    cin >> tmp;
    if(tmp < miny){
      miny = tmp;
    }
  }
  
  if(miny > maxx){
    cout << "No War" << endl;
  } else { 
    cout << "War" << endl;
  }
  
}

Measured memory_bytes: 256
import math

N = int(raw_input())
CSF = [map(float, raw_input().split()) for _ in range(N-1)]

for i in range(N-1):
    ans = CSF[i][0] + CSF[i][1]
    for j in range(i+1, N-1):
        C, S, F = CSF[j][0], CSF[j][1], CSF[j][2]
        if S < ans:
            n = math.ceil((ans - S) / F)
            ans = C + S + F * n
        else:
            ans = C + S
 
    print int(ans)

print 0

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int main()
{
    int n;
    cin>>n;
    double ans = 0.0;
    REP(i,n) {
        double x;
        string u;
        cin>>x>>u;
        if (u == "BTC")
            x *= 380000.0;
        ans += x;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

vector<vector<ll>> dp;
string s1,s2;


ll lcs(ll i,ll j){
    if(i==s1.length() || j== s2.length()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(s1[i]==s2[j]){
        if(dp[i+1][j+1]==-1){
            dp[i+1][j+1] = lcs(i+1,j+1);
        }
        return 1+lcs(i+1,j+1);
    }
    if(dp[i+1][j]==-1){
        dp[i+1][j] = lcs(i+1,j);
    }
    if(dp[i][j+1]==-1){
        dp[i][j+1] = lcs(i,j+1);
    }

    return max(lcs(i+1,j),lcs(i,j+1));
}




int main() {
    fastio
    cin>>s1>>s2;

    dp.resize(4000,vector<ll>(4000));
    for(int i=0;i<4000;i++){
        for(int j=0;j<4000;j++){
            dp[i][j]=-1;
        }
    }
    dp[0][0] = lcs(0,0);
    // for(int i=0;i<s1.length();i++){
    //     for(int j=0;j<s2.length();j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }    
    ll i=0,j=0;
    string ans="";
    while(i<s1.size() && j<s2.size()){
        if(s1[i]==s2[j]){
            ans+=s1[i];
            i++,j++;
            continue;
        }
        if(dp[i+1][j]>=dp[i][j+1]){
            i++;
        }else{
            j++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 128844
#include <iostream>
#include <algorithm>
#include <climits>
#include <bitset>

using namespace std;

int P[10], p[10], c[10];

int main(void){
    int D, G;
    int sub;
    int ans = INT_MAX;
    
    cin >> D >> G;
    
    for(int i = 0; i < D; i++){
        cin >> sub;
        p[i] = sub;
        cin >> sub;
        c[i] = sub;
    }
    
    // for(int i = 0; i < (1 << D); i++){
    //     cout << bitset<4>(i) << endl;
    // }
    
    for(int i = 0; i < (1 << D); i++){
        int cnt = 0;
        int sum = G;
        
        for(int j = 0; j < D; j++){
            P[j] = p[j];
        }
        
        for(int j = D - 1; j >= 0; j--){
            if(i & (1 << j)){
                cnt += p[j];
                sum -= 100 * (j + 1) * p[j] + c[j];
                P[j] = 0;
            }
            
            if(sum <= 0){
                break;
            }
        }
        
        if(sum > 0){
            for(int j = D - 1; j >= 0; j--){
                if(P[j] > 0){
                    while(P[j] > 0 && sum > 0){
                        cnt++;
                        sum -= 100 * (j + 1);
                        P[j]--;
                    }
                }
                
                if(sum <= 0){
                    break;
                }
            }
        }

        ans = min(ans, cnt);
    }
    
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int i=0,j,x;
  float f;
  vector<pair<float,int> >v,w;
  for(;i<3;i++){
    for(j=0;j<8;j++)
      scanf("%d%f",&x,&f),v.push_back(make_pair(f,x));
    sort(v.begin(),v.end());
    printf("%d %.2f\n%d %.2f\n",v[0].second,v[0].first,v[1].second,v[1].first);
    w.push_back(make_pair(v[2].first,v[2].second));
    w.push_back(make_pair(v[3].first,v[3].second));
    v.clear();
  }
  sort(w.begin(),w.end());
  printf("%d %.2f\n%d %.2f\n",w[0].second,w[0].first,w[1].second,w[1].first);
}

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

int main(){

	int a , b , c ;
	cin >> a >> b >> c ;

	if( a < b ){
			if ( b < c ){
			cout<< "Yes"<< endl;
			}else{
			cout<< "No"<< endl;
			}
	}else{
	cout<< "No"<< endl;
	}

	return 0;
}


Measured memory_bytes: 3080
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

int n,k;
const int MAX_N = 1000100;
int a[MAX_N];
bool dp[MAX_N];

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

  cin >> n >> k;
  REP(i, n) {
    cin >> a[i];
  }
  //1:first win, 0:second win
  //dp[k]:= k個の局面で勝ち負け
  
  FOR(i, 1, k+1){
    REP(j, n){
      if(i-a[j]>=0){
	dp[i] |= !dp[i-a[j]];
      }
    }
  }
  /*
  FOR(i,1,k+1) cout << dp[i] << " ";
  cout << endl;
  */
  cout << (dp[k] ? "First" : "Second") << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    long long int n;
    cin >> n;
    vector<long long int> a(5);
    
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    long long int ans = n/a[0];
    if (n % a[0] > 0) {
        ans++;
    }
    ans += 4;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=LONG_LONG_MAX;
const int inf=(1<<30)-1;


int main(){
      ll n,l;
      cin>>n>>l;
      ll a[n];
      rep0(i,n) cin>>a[i];
      bool ok=false;
      ll pos=0;
      rep0(i,n-1){
            if(a[i]+a[i+1]>=l){
                  ok=true;
                  pos=i;
                  break;
            }
      }
      ll ans[n];
      rep0(i,n-1){
            ans[i]=i+1;
      }
      reverse(ans+pos,ans+n-1);
      if(ok) {
            cout<<"Possible"<<endl;
            rep0(i,n-1) cout<<ans[i]<<endl;
      }
      else cout<<"Impossible"<<endl;
      return 0;
}

Measured memory_bytes: 2432
import java.util.*;

public class Main {
    
    long INF = Long.MAX_VALUE;
    long[] dp;
    int N;
    ArrayList<ArrayList<Integer>> G;
    int MAX_M = 100000;
    int MAX_N = 100000;
    
    public static void main(String[] args) {
        new Main().solve();
    }
    
    void solve() {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int M = sc.nextInt();
        dp = new long[N + 1];
        Arrays.fill(dp, -1);
        G = new ArrayList<ArrayList<Integer>>(N + 1);
        for (int i = 0; i <= N; i++) {
            G.add(i, new ArrayList<>());
        }
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            G.get(x).add(y);
        }
        long res = 0;
        for(int v = 1;v <= N;v++){
            res = Math.max(res, rec(v));
        }
        System.out.println(res);
    }

    // dp[i]: iを始点としたときの最大の最大値
    long rec(int i) {
        long res = 0;
        if (dp[i] != -1) {
            return dp[i];
        }
        for (int j : G.get(i)) {
            res = Math.max(res, rec(j) + 1);
        }
        return dp[i] = res;
    }
}


Measured memory_bytes: 107388
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
#define debug puts("wzpakking")
#define y1 ysghysgsygsh
using namespace std;
const int N=100005;
int n,X[N],L[N],q[N*2],t[N*2],id[N];
void change(int k,int v){
	for (;k<=*q;k+=k&(-k)) t[k]=max(t[k],v);
}
int ask(int k){
	int ans=0;
	for (;k;k-=k&(-k)) ans=max(ans,t[k]);
	return ans;
}
bool cmp(int x,int y){
	return X[x]<X[y];
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d%d",&X[i],&L[i]);
	For(i,1,n) q[++*q]=X[i]+L[i],q[++*q]=X[i]-L[i];
	For(i,1,n) id[i]=i;
	sort(id+1,id+n+1,cmp);
	sort(q+1,q+*q+1);
	For(i,1,n){
		int p1=lower_bound(q+1,q+*q+1,X[id[i]]-L[id[i]])-q;
		int p2=lower_bound(q+1,q+*q+1,X[id[i]]+L[id[i]])-q;
		change(p2,ask(p1)+1);
	}
	printf("%d\n",ask(*q));
}

Measured memory_bytes: 2944
N = int(input())
S = list(input())

ans = [0] * N
#リーダーより東の東向きの人
ans[0] = S[1:].count("E")

#リーダーを東にずらしていく
for i in range(1, N):
    ans[i] = ans[i-1]
    if S[i-1] == "W":
        ans[i] += 1
    if S[i] == "E":
        ans[i] -= 1

#print("ans : {}".format(ans))
print(min(ans))

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

class B
{
	static double[] Read() => Console.ReadLine().Split().Select(double.Parse).ToArray();
	static void Main()
	{
		var h = Read();

		// Vector2 は float のため、精度が足りません。
		var p1 = new V(h[0], h[1]);
		var p2 = new V(h[2], h[3]);
		var p0 = p2 - p1;
		var e = p0 / p0.Norm;

		var q = int.Parse(Console.ReadLine());
		var r = new int[q].Select(_ => Read())
			.Select(x => new V(x[0], x[1]))
			.Select(p =>
			{
				var p_ = p - p1;
				return p + 2 * (V.Dot(p_, e) * e - p_);
			});
		Console.WriteLine(string.Join("\n", r));
	}
}

struct V
{
	public double X, Y;
	public V(double x, double y) { X = x; Y = y; }

	public static V operator +(V v) => v;
	public static V operator -(V v) => new V(-v.X, -v.Y);
	public static V operator +(V v1, V v2) => new V(v1.X + v2.X, v1.Y + v2.Y);
	public static V operator -(V v1, V v2) => new V(v1.X - v2.X, v1.Y - v2.Y);
	public static V operator *(double c, V v) => new V(v.X * c, v.Y * c);
	public static V operator *(V v, double c) => new V(v.X * c, v.Y * c);
	public static V operator /(V v, double c) => new V(v.X / c, v.Y / c);

	public static bool operator ==(V v1, V v2) => v1.X == v2.X && v1.Y == v2.Y;
	public static bool operator !=(V v1, V v2) => !(v1 == v2);
	public override bool Equals(object obj) => obj is V && this == (V)obj;
	public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode();
	public override string ToString() => $"{X:F9} {Y:F9}";

	public double Norm => Math.Sqrt(X * X + Y * Y);
	public static double Dot(V v1, V v2) => v1.X * v2.X + v1.Y * v2.Y;
}



Measured memory_bytes: 18556
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    int n,a,b; 
	cin >> n;
    vector<vector<int>> g(n);
    vector<pair<int, int>> vp;
    for (int i=0; i<n-1; i++) 
	{
        cin>>a>>b;a--;b--;
        g[a].push_back(b);
        g[b].push_back(a);
        vp.push_back(make_pair(a,b));
    }
    int k=0;
    map<pair<int,int>,int> I;
    vector<int> cs(n, 0);
    vector<int> used(n, 0);
    queue<int> que;que.push(0);
    used[0] = 1;
    while(!que.empty()) 
	{
        int v=que.front();que.pop();
        k=max(k,(int)g[v].size());
        int cur=1;
        for(int u:g[v]) 
		{
            if(used[u]) continue;
            if(cur==cs[v]) cur++;
            cs[u]=cur;
            I[make_pair(u,v)]=cur;
            I[make_pair(v,u)]=cur;
            cur++;
            used[u]=1;
            que.push(u);
        }
    }
    cout<<k<<endl;
    for(auto p:vp) cout<<I[p]<<endl;
    return 0;
}



Measured memory_bytes: 20084
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

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

	return 0;
}

Measured memory_bytes: 3652
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#define pi 3.1415926536
using namespace std;

//int sb[200005];
//int sw[200005];
int main()
{
	char s[200005];
	int nw = 0,nb = 0;
	long long sum = 0;
	int n;
	scanf("%s",s + 1);
	n = strlen(s + 1);
//	printf("%d",n);
	for(int i = 1; i <= n; i++){
		if(s[i] == 'W'){ 
			//nw++;
			sum += nb;
			//sw[nw] = nb;
		}
		if(s[i] == 'B') nb++;
	}
	//printf("%d %d ", nb, nw); 
	/*for(int i = 1; i <= nw; i++){
		sum += sw[i]; 
	}*/
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 384
//日本語が読めないABCやってます。問題名は見えます。
#include <iostream>
#include <algorithm>
using namespace std;

int n, k;
int p[1000];

int main() {
	int i;
	
	cin >> n >> k;
	for (i = 0; i < n; i++) cin >> p[i];
	sort(p, p + n);
	
	int ans = 0;
	for (i = 0; i < k; i++) ans += p[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3544
def main():
  n, m = input_list()
  s = input()
  t = input()
  gcm = fractions.gcd(n, m)
  lcm = (n*m)//gcm
  ng = n//gcm
  mg = m//gcm
  for i in range(gcm):
    if s[ng*i] != t[mg*i]:
      print(-1)
      exit(0)
  print(lcm)
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c 

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 5652
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000000000000LL
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
struct jewel
{
    ll val,num,color;
};
bool cmp(jewel x,jewel y)
{
    return x.val>y.val;
}
ll n,k,c,val;
multiset<ll> s[MAXN];
vector<jewel> v;
multiset<ll> P,Q,R,S;
multiset<ll> T;
//P: valid additional taken
//Q: valid untaken
//R: valid taken pair
//S: invalid untaken pair
//T: invalid untaken triple
//possible transformations:
//+Q
//-P +S
//-R +T
bool valid[MAXN];
ll save2[MAXN];
ll save3[MAXN];
int main()
{
    memset(save2,0,sizeof(save2));
    memset(save3,0,sizeof(save3));
    scanf("%lld%lld",&n,&k);
    for(ll i=1;i<=n;i++)
    {
        scanf("%lld%lld",&c,&val);
        s[c].insert(val);
    }
    for(ll i=1;i<=k;i++)
    {
        if(!s[i].size()) continue;
        ll res=0;
        auto it=s[i].end(); it--; res+=*it; it--; res+=*it;
        v.push_back((jewel){res,2,i}); S.insert(res); save2[i]=res;
        ll cnt=0;
        while(it!=s[i].begin())
        {
            it--;
            v.push_back((jewel){2*(*it),1,i});
            if(!cnt) {T.insert(res+*it); save3[i]=res+*it;}
            cnt++;
        }
    }
    sort(v.begin(),v.end(),cmp);
    ll now=0;
    ll ans=0;
    memset(valid,false,sizeof(valid));
    for(ll i=1;i<=n;)
    {
        if(v[now].num==1)
        {
            assert(valid[v[now].color]);
            ans+=v[now].val/2;
            P.insert(v[now].val/2);
            assert(Q.count(v[now].val/2));
            Q.erase(Q.find(v[now].val/2));
            now++;i++;
            printf("%lld\n",ans);
        }
        else
        {
            ll choices=-INF;
            if(Q.size())
            {
                auto it=Q.end(); it--;
                choices=max(choices,*it);
            }
            if(P.size()&&S.size())
            {
                auto it=P.begin();
                ll tmp=*it;
                it=S.end(); it--;
                choices=max(choices,*it-tmp);
            }
            if(R.size()&&T.size())
            {
                auto it=R.begin();
                ll tmp=*it;
                it=T.end(); it--;
                choices=max(choices,*it-tmp);
            }
            if(choices==-INF) puts("-1"); else printf("%lld\n",ans+choices);
            ans+=v[now].val;
            ll c=v[now].color;
            assert(!valid[c]);
            valid[c]=true;
            S.erase(S.find(save2[c]));
            if(save3[c]) T.erase(T.find(save3[c]));
            R.insert(save2[c]);
            auto it=s[c].end(); it--; it--; 
            while(it!=s[c].begin())
            {
                it--;
                Q.insert(*it);
            }
            now++;i+=2;
            printf("%lld\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 39276
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair < ll, int > PLI;


#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

#define fname ""

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e2 + 6;

int n, m;
bool a[N][N];
int d[N][N];

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

    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #else
        //freopen(fname".in", "r", stdin);
        //freopen(fname".out", "w", stdout);
    #endif

    cin >> n >> m;
    forn(i, 1, n) {
        forn(j, 1, m) {
            char x;
            cin >> x;
            a[i][j] = (x == '#');
        }
    }

    forn(i, 1, n) {
        forn(j, (i == 1 ? 2 : 1), m) {
            d[i][j] = oo;
            if (i > 1) d[i][j] = min(d[i][j], d[i - 1][j] + (a[i - 1][j] != a[i][j]));
            if (j > 1) d[i][j] = min(d[i][j], d[i][j - 1] + (a[i][j - 1] != a[i][j]));
        }
    }

    if (a[1][1]) {
        cout << (d[n][m] + 2) / 2 << "\n";
    }
    else {
        cout << (d[n][m] + 1) / 2 << "\n";
    }

    return 0;
}


Measured memory_bytes: 384
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
  long []po=new long[n];
  long sum=0;
  long a[]=new long[n];
  for(int i=0;i<n;i++){
  	po[i]=sc.nextLong();
    a[i]=(i==0)?po[0]:a[i-1]+po[i];
    sum+=po[i];
  }
  long ans=0;
  for(int i=0;i<n-1;i++){
  	ans+=(po[i]%1000000007)*((sum-a[i])%1000000007);
    ans%=1000000007;
  }System.out.println(ans);
}
}

Measured memory_bytes: 64004
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a.begin(), a.end());
    vector<pii> b;
    int c = 1;
    for (int i = 1; i < n; ++i) {
        if (a[i] == a[i - 1])
            ++c;
        else {
            b.push_back(pii(a[i - 1], c));
            c = 1;
        }
    }
    b.push_back(pii(a[n - 1], c));
    if ((n % 3) != 0) {
        if ((b.size() == 1) && (b[0].first == 0)) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
        return;
    }
    if (b.size() > 3) {
        cout << "No\n";
        return;
    }
    if (b.size() == 1) {
        if (b[0].first == 0) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
        return;
    }
    int m = n / 3;
    if (b.size() == 3) {
        if ((b[0].first ^ b[1].first ^ b[2].first) == 0) {
            if ((b[0].second == m) && (b[1].second == m) && (b[2].second == m)) {
                cout << "Yes\n";
                return;
            }
        }
        cout << "No\n";
        return;
    }
    if ((b[0].second == m) && (b[1].second == 2 * m)) {
        if (b[0].first == 0) {
            cout << "Yes\n";
            return;
        }
    }
    if ((b[0].second == 2 * m) && (b[1].second == m)) {
        if (b[1].first == 0) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
    return;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


Measured memory_bytes: 1784