akhauriyash/Code-Regression huggingface dataset:
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
#define M_PI           3.14159265358979323846  /* pi */
#define sec second
#define fir first
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repe(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define entire(a) (a).begin(),(a).end()
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
ll dp[101][100001];
void solve()
{
	ll n, w;
	cin >> n >> w;
	ll weight[n], value[n];
	rep(i, n)
	cin >> weight[i] >> value[i];
	rep(i, n) {
		rep(j, w + 1) {
			if (i == 0) {
				if (j >= weight[i])
					dp[i][j] = value[i];
				else
					dp[i][j] = 0;
				// cout << "yo\n";
			} else {
				if (j < weight[i])
					dp[i][j] = dp[i - 1][j];
				else
					dp[i][j] = max(dp[i - 1][j], value[i] + dp[i - 1][j - weight[i]]);
			}
		}
	}
	cout << dp[n - 1][w] << endl;
}




int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fast
	int T = 1;
	// cin >> T;
	while (T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 81788
n,l=map(int,input().split())

if l>=0:
    print(int((2*l+n)*(n-1)/2))
else:
    if abs(l)<n:
        print(int((2*l+n-1)*n/2))
    else:
        print(int((2*l+n-2)*(n-1)/2))

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

int main() {
    long long K;
    cin >> K;
    double X, Y;
    long long ans = 0;
    if ((K%2 == 0)||(K%5 == 0)) {
        ans = -1;
    }else{
        long long rep = 0;
        for (long long i = 1; true; i++) {
            rep = (rep*10 + 7)%K;
            if (rep == 0) {
                ans = i;
                break;
            }
        }
    }

    cout << ans << endl;
 
    
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VL;
typedef vector<pair<ll, ll>> VPI;
typedef pair<ll, ll> PLL;
typedef map<ll, ll> MLL;
#define EPS 1e-9
#define pb push_back
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

ll max(ll a, ll b, ll c)
{
    ll max = (a > b && a > c) ? a : (b > c) ? b : c;
    return max;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1), c(n + 1);
    FOR(i, 1, n + 1)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    ll dp[n + 1][3] = {0};
    dp[1][0] = a[1];
    dp[1][1] = b[1];
    dp[1][2] = c[1];
    FOR(i, 2, n + 1)
    {
        dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = c[i] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max(dp[n][0], dp[n][1], dp[n][2]);
    return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;
  
  if (B == 1){
    cout << 0 << endl;
    return 0;
  }
  
  int i = 0;
  while(true){
    if ((A - 1) * (i + 1) + 1 >= B){
      cout << i + 1 << endl;
      return 0;
    }
    i++;
  }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin >> a >> b >> c;
    if (a==b&&b==c) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
	
	string s,s1;
	
	cin>>s>>s1;
	
	string ss=s+s1;
	
	//string into int 
	stringstream geek(ss);
	int x;
	geek>>x;
	
	if(fmod(sqrt(x),1)==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
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;}

void solve(){
    ll n,q;cin>>n>>q;
    string s;cin>>s;
    vector<char> t(q);
    vector<char> d(q);
    rep(i,q)cin>>t[i]>>d[i];
    ll lok=n;
    ll lng=-1;
    while(lok-lng>1){
        ll mid=(lok+lng)/2;
        ll tmp=mid;
        rep(i,q){
            if(s[tmp]==t[i]){
                tmp+=d[i]=='L'?-1:1;
            }
            if(tmp<0)break;
        }
        if(tmp<0)lng=mid;
        else lok=mid;
    }
    ll rng=n;
    ll rok=-1;
    while(rng-rok>1){
        ll mid=(rok+rng)/2;
        ll tmp=mid;
        rep(i,q){
            if(s[tmp]==t[i]){
                tmp+=d[i]=='L'?-1:1;
            }
            if(tmp>=n)break;
        }
        if(tmp>=n)rng=mid;
        else rok=mid;
    }
    cerr<<lok<<' '<<rok<<'\n';
    cout<<max(0ll,rok-lok+1)<<'\n';
}

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


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

int main(void) {
  int N, ans;
  cin >> N;
  int V[N], C[N];
  
  for(int i=0; i<N; i++) cin >> V[i];
  for(int i=0; i<N; i++) cin >> C[i];
  
  for(int i=0; i<N; i++)
    if(V[i]-C[i] >= 0) ans += (V[i]-C[i]);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <int,int> PII;
typedef pair <ll, ll> PLL;
typedef pair <int,string> PIS;
typedef vector <int> vec;
typedef priority_queue<int> PQ;
#define endl '\n'
#define pi 3.141592653589793
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define fori(z,n) for(int i=z;i<n;i++)
#define forii(z,n) for(int i=z;i<=n;i++)
int maxElement(int arr[],int n)
{
    int maxi=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]>maxi)
            maxi=arr[i];
    }
    return maxi;
}
int minElement(int arr[],int n)
{
    int mini=arr[0];
    for(int i=1;i<n;i++)
    {
        if(arr[i]<mini)
            mini=arr[i];
    }
    return mini;
}
string trim(const string& str)
{
    size_t first = str.find_first_not_of(' ');
    if (string::npos == first)
    {
        return str;
    }
    int last = str.find_last_not_of(' ');
    return str.substr(first, (last - first + 1));
}
int n,m,dp[100005];
bool vis[100005];
void dfs(vector<vector<int>> &v, int i)
{
    vis[i]=true;
    for(auto u:v[i])
    {
        if(!vis[u])
            dfs(v,u);
        dp[i]=max(dp[i],dp[u]+1);
    }
}
int main() 
{ 
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>m;
    vector<vector<int>> v(n+1);
    fori(0,m)
    {
        int p,q;cin>>p>>q;
        v[p].push_back(q);
    }
    memset(vis,false,sizeof(vis));
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
            dfs(v,i);
    }
    int ans=0;
    fori(1,n+1) ans=max(dp[i],ans);
    cout<<ans<<endl;
    cerr<<"Time elapsed"<<1.0*clock()/CLOCKS_PER_SEC<<"s\n";
    return 0;
}


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

#define OUT(x)  cerr << #x << " = " << x << endl;
#define all(x)  x.begin(), x.end()
#define mp      make_pair
#define pii     pair<int, int>
#define piii    pair<int, pair<int, int>>

int main() {
        int n;
        cin >> n;
        vector<long long> a(n);
        for (int i = 0; i < n; i ++) {
                cin >> a[i];
        }
        sort(all(a));
        reverse(all(a));
        long long ans = 1;
        int cnt = 0;
        for (int i = 0; i < n; i ++) {
                if (a[i] == a[i + 1]) {
                        ans *= a[i];
                        i ++;
                        cnt ++;
                        if (cnt == 2) break;
                }
        }
        if (cnt < 2) cout << 0 << endl;
        else cout << ans << endl;
        return 0;
}



Measured memory_bytes: 1024
#include <cstdio>

#define fin stdin
#define fout stdout
//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");

int main() {
    int m, d, ans = 0;
    fscanf(fin, "%d%d", &m, &d);

    for (int i = 2; i <= 9; i++)
        for (int j = 2; j <= 9; j++)
            ans += (i * j <= m && 10 * i + j <= d);

    fprintf(fout, "%d\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <assert.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll INF = 1e18;

int main() {
    ll n, c;
    cin >> n >> c;
    VL x(n), v(n);
    REP(i,n){
        x[i] = lin();
        v[i] = lin();
    }

    VL pos(n);
    ll sum = 0;
    REP(i,n){
        sum += v[i];
        pos[i] = sum - x[i];
    }
    VL mal(n, -INF);
    mal[0] = pos[0];
    REP(i,n-1){
        mal[i+1] = max(mal[i], pos[i+1]);
    }

    VL neg(n);
    sum = 0;
    FORR(i,n-1,0){
        sum += v[i];
        neg[i] = sum - (c - x[i]);
    }
    VL mar(n, -INF);
    mar[n-1] = neg[n-1];
    FORR(i,n-1,1){
        mar[i-1] = max(mar[i], neg[i-1]);
    }

    ll ans = 0;
    REP(i,n){
        ans = max(ans, pos[i]);
        ans = max(ans, neg[i]);
    }

    sum = 0;
    FORR(i,n-1,1){
        sum += v[i];
        ans = max(ans, sum - 2 * (c - x[i]) + mal[i-1]);
    }

    sum = 0;
    REP(i,n-1){
        sum += v[i];
        ans = max(ans, sum - 2 * x[i] + mar[i+1]);
    }
    
    cout << ans << endl;

    return 0;
}


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

int main(void){
	int n, i, j, minj, temp, count=0;
	int *a;
	scanf("%d", &n);
	a = malloc(n*sizeof(int));
	for(i=0;i<n;i++){
		scanf("%d", &a[i]);
	}
	for(i=0;i<n-1;i++){
		minj=i;
		for(j=i+1;j<n;j++){
			if(a[j]<a[minj]){
				minj=j;
			}
		}
		if(a[i]!=a[minj]){
			temp=a[i];
			a[i]=a[minj];
			a[minj]=temp;
			count++;
		}
	}
	printf("%d", a[0]);
	for(i=1;i<n;i++){
		printf(" %d", a[i]);
	}
	printf("\n");
	printf("%d\n", count);
}

Measured memory_bytes: 1816
from math import sqrt
N = int(input())
A = []
for i in range(N):
  A.append(list(map(int, input().split())))
  
avg = 0
for i in range(N):
  for j in range(i+1,N):
    avg += sqrt( (A[i][0]-A[j][0]) ** 2 + (A[i][1]-A[j][1]) ** 2) * 2 / N
    #print(i,j)
    
print(avg)

Measured memory_bytes: 3064
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
using namespace std;
#define U(v) \
cerr << #v << ": " << (v) << endl

int main() {
    int N, K;
    bool b[10];
    fill_n(b, 10, true);

    cin >> N >> K;
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        b[d] = false;
    }

    for (int i = N; ; ++i) {
        bool ok = true;
        for (int j = i; j; j /= 10) {
            int k = j % 10;
            if (!b[k]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

namespace atcoder.abc173.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = getIntParam();

            Console.WriteLine(N % 1000 == 0 ? 0 : 1000 - (N % 1000));
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


Measured memory_bytes: 27396
import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

bool[][] road;
int h, w;

alias tuple = Tuple!(int,int,int);

int solve(int x1, int y1) {
  bool[][] checked = new bool[][](w,h);
  for(int i=0; i<w; i++) for(int j=0; j<h; j++) checked[i][j] = !road[i][j];
  DList!tuple queue;
  queue.insertBack(tuple(x1,y1,0));
  int depth;
  while(!queue.empty) {
    auto t = queue.front;
    queue.removeFront;
    x1=t[0];
    y1=t[1];
    depth = t[2];
    if(checked[x1][y1]) continue;
    if(y1+1<h && !checked[x1][y1+1]) queue.insertBack(tuple(x1,y1+1,depth+1));
    if(x1+1<w && !checked[x1+1][y1]) queue.insertBack(tuple(x1+1,y1,depth+1));
    if(y1-1>=0 && !checked[x1][y1-1]) queue.insertBack(tuple(x1,y1-1,depth+1));
    if(x1-1>=0 && !checked[x1-1][y1]) queue.insertBack(tuple(x1-1,y1,depth+1));
    checked[x1][y1] = true;
  }
  return depth;
}

void main() {
  readf("%d %d\n", &h, &w);
  road = new bool[][](w,h);
  for(int i=0; i<h; i++) {
    auto s = readln.chomp;
    for(int j=0; j<w; j++) road[j][i] = s[j]=='.';
  }

  int maximum = 0;
  for(int x1=0; x1<w; x1++) for(int y1=0; y1<h; y1++) {
    if(road[x1][y1]) maximum = max(solve(x1,y1), maximum);
  }
  maximum.writeln;
}



Measured memory_bytes: 1276
#include <string>
#include <stack>
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){
  string word;
  stack<int> S;
  int a, b;

  while(cin >> word){
    if (word == "+"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b+a);
    } else if (word == "-"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b-a);
    } else if (word == "*"){
      a = S.top();
      S.pop();
      b = S.top();
      S.pop();
      S.push(b*a);
    } else {
      a = atoi(word.c_str());
      S.push(a);
    }
  }

  cout << S.top() << endl;
}



Measured memory_bytes: 3172
import sys
readline = sys.stdin.readline
write = sys.stdout.write

cnt = 0
all_visited = False
def dfs(link, V, i):
    global cnt
    global all_visited
    for j in range(N):
        if V[j] == 0:
            all_visited = False
            break
        all_visited = True
    
    if all_visited == True:
        cnt += 1
        return
    
    adj = len(link[i])
    for j in range(adj):
        if V[link[i][j]] == 0:
            V[link[i][j]] = 1
            dfs(link, V, link[i][j])
            V[link[i][j]] = 0


a = list(map(int,input().split()))
N = a[0]
M = a[1]
link = [[] for i in range(N)]
visited = [0 for i in range(N)]
for i in range(M):
    temp = list(map(int,input().split()))
    link[temp[0]-1].append(temp[1]-1)
    link[temp[1]-1].append(temp[0]-1)
visited[0] = 1
dfs(link, visited, 0)
print(str(cnt))

Measured memory_bytes: 3064
#pragma GCC optimize "trapv" 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep(i,a,n)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
vector<int>g[N+5];
int lvl[N+5];
int vis[N];
void dfs(int r){
    vis[r]=1;
    for(auto i:g[r]){
        if(!vis[i]){
           vis[i]=1; 
           dfs(i);
        } 
        lvl[r]=max(lvl[r],1+lvl[i]);
    }   
}
int solve(){
  int n,m;cin>>n>>m;          
  rep3(m){
      int a,b;cin>>a>>b;
      g[a].pb(b);
  } 
  for(int i=1;i<=n;i++){
      if(!vis[i])dfs(i);
  }
  int ma=0;
  for(int i=1;i<=n;i++){
      if(ma<lvl[i])ma=lvl[i];
  }         
  cout<<ma<<endl;
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef cat
    cat();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

Measured memory_bytes: 8576
// https://not-522.appspot.com/contest/4799945443901440
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF= 1LL << 60;
#define REP(i,n) for(ll i=0; i<n; i++)
#define FOR(i,a,n) for(ll i=a; i<n; i++)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll cntl= 0;
    ll cntr= 0;

    REP(i,n){
        //必要な挿入数を計算
        if(s[i]=='(') cntl++;
        else {
            cntr++;
            if(cntl>0){
                cntl--;
                cntr--;
            }
        }
    }

    REP(i, cntr){
        cout << '(';
    }
    cout << s;
    REP(i, cntl){
        cout << ')';
    }
    cout << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
	
		int ans = (A+B)%24;
		
		System.out.println(ans);

	}

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i];
    if(i == SZ(s)-1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  // printv(a);
  vector<int> dp(n);
  map<int, int> m;
  dp[0] = 1;
  dp[1] = 1;
  m[a[0]] = 1;
  for(int i=2;i<n;++i) {
    dp[i] = dp[i-1];
    if(a[i] != a[i-1]) {
      dp[i] += m[a[i]];
    }
    dp[i] %= MOD;
    m[a[i-1]] = dp[i-1];
  }
  // printv(dp);
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 11136
import java.util.Scanner;

class Main
{
    public static void main(String [] args)
    {
        Scanner scan = new Scanner(System.in);
       
        int a = scan.nextInt();

        int b = scan.nextInt();
        

        System.out.print(a * b);
        
        System.out.print(" ");

        System.out.println((a * 2) + (b * 2));
    }  
}



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

public class Main {
	void run() {
		String need = "keyence";
		String s = in.next();
		for (int i = 0; i <= need.length(); i++) {
			String t = s.substring(0, i) + s.substring(s.length() - need.length() + i);
			if (t.equals(need)) {
				out.println("YES");
				return;
			}
		}
		out.println("NO");
	}

	static MyScanner in;
	static PrintWriter out;

	public static void main(String[] args) throws IOException {
		boolean stdStreams = true;
		String fileName = Main.class.getSimpleName().replaceFirst("_.*", "").toLowerCase();
		String inputFileName = fileName + ".in";
		String outputFileName = fileName + ".out";
		
		Locale.setDefault(Locale.US);
		BufferedReader br;
		if (stdStreams) {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		} else {
			br = new BufferedReader(new FileReader(inputFileName));
			out = new PrintWriter(outputFileName);
		}
		in = new MyScanner(br);
		int tests = 1;//in.nextInt();
		for (int test = 0; test < tests; test++) {
			//out.print("Case #" + (test + 1) + ": ");
			new Main().run();
		}
		br.close();
		out.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		MyScanner(BufferedReader br) {
			this.br = br;
		}
		
		void findToken() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		
		String next() {
			findToken();
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


Measured memory_bytes: 22740
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int n;
    cin >> n;
    int k = 1;
    while (k * (k - 1) < 2 * n) ++k;
    if (k * (k - 1) != 2 * n)
    {
        cout << "No\n";
    }
    else
    {
        cout << "Yes\n";
        cout << k << "\n";
        int front = 1;
        rep (i, k)
        {
            cout << k - 1 << " ";
            int temp = i;
            rep (j, k - 1)
            {
                if (j < i)
                {
                    cout << temp << " ";
                    temp += k - j - 2;
                }
                else
                {
                    cout << front << " ";
                    ++front;
                }
            }
            cout << "\n";
        }
    }

    return 0;
}



Measured memory_bytes: 1408
s = input()

#±の入る場所
for bit in range(1<<3): 
    ans = int(s[0]) #sをリストとして見る
    f = s[0] #最後に出力する数式

#±に置き換え
    for i in range(3): 
        if bit&(1 << i): #bitのi桁目が0か1か
            ans += int(s[i+1])
            f += "+"
        else:
            ans -= int(s[i+1])
            f += "-"
        f += s[i+1]
    if ans == 7:
        print(f + "=7")
        exit()
        

Measured memory_bytes: 61884
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (h, w, a, b) = (v[0], v[1], v[2], v[3]);
    let big_int = 1000_000_000 + 7;

    let fact = ModFactorial::new(200000, big_int).fact;
    let inv_fact = (0..fact.len())
        .map(|x| mod_inverse(fact[x as usize], big_int))
        .collect::<Vec<_>>();

    let mut ans = 0;
    let mut temp1 = 1;
    let res_h = h - 1;
    let res_w = w - b - 1;
    let mut temp2 = ModBinominal::new(res_h + res_w, big_int, &fact, &inv_fact).bin[res_h as usize];
    for i in 0..h - a {
        ans += (temp1 * temp2) % big_int;
        ans %= big_int;
        temp1 *= b + i;
        temp1 %= big_int;
        temp1 *= mod_inverse(i + 1, big_int);
        temp1 %= big_int;

        temp2 *= res_h - i;
        temp2 %= big_int;
        temp2 *= mod_inverse(res_h + res_w - i, big_int);
        temp2 %= big_int;
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn extgcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    let mut d = a;
    if b == 0 {
        *x = 1;
        *y = 0;
    } else {
        d = extgcd(b, a % b, y, x);
        *y -= (a / b) * (*x);
    }
    return d;
}

fn mod_inverse(a: i64, m: i64) -> i64 {
    let mut x: i64 = 0;
    let mut y: i64 = 0;
    extgcd(a, m, &mut x, &mut y);
    (m + x % m) % m
}

struct ModFactorial {
    fact: Vec<i64>,
}

// returns n! under mod m
impl ModFactorial {
    fn new(n: i64, m: i64) -> ModFactorial {
        let mut fact = vec![1; n as usize + 1];
        for i in 2..fact.len() {
            fact[i] = (i as i64 * fact[i - 1]) % m;
        }
        ModFactorial { fact: fact }
    }
}

// returns bin[i] = nCi under mod m
struct ModBinominal {
    bin: Vec<i64>,
}

impl ModBinominal {
    fn new(n: i64, m: i64, fact: &Vec<i64>, inv_fact: &Vec<i64>) -> ModBinominal {
        let mut bin = vec![1; n as usize + 1];
        if n == 0 {
            return ModBinominal { bin: bin };
        }
        for i in 1..n + 1 {
            let a2 = inv_fact[i as usize] % m;
            let a3 = inv_fact[(n - i) as usize] % m;
            bin[i as usize] = fact[n as usize] * ((a2 * a3) % m) % m;
        }
        ModBinominal { bin: bin }
    }
}


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

double a[200000];
double b[200001];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    a[i] = (double)(p + 1) / 2;
  }
  partial_sum(a, a + n, b + 1);
  
  double mx = 0;
  for (int i = 0; i < n; ++i) {
    int j = i + k;
    if (j > n) continue;
    mx = max(mx, b[j] - b[i]);
  }
  
  cout << setprecision(16) << fixed << mx << endl;
}

Measured memory_bytes: 3328
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

n = int(input())
A = [int(i) for i in input().split()]

tmp = 0
res = 1

A = sorted(A)
for i in range(n):
    res *= A[i]
    if res > 10 ** 18:
        res = -1
        break
    if res == 0:
        break

print(res)


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


void solve(long long N, std::string S){
    long long nlw=0, nre=0;
    for(auto it=S.rbegin(); it<S.rend(); it++)
        if(*it=='E')nre++;

    auto ans = (long long)pow(10,10);
    for(auto it=S.begin(); it<S.end(); it++){
        if(*it=='E')nre--;
        ans = min(ans, nlw+nre);
        if(*it=='W')nlw++;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 1028
/*
                  ,     \    /      ,
                 / \    )\__/(     / \
                /   \  (_\  /_)   /   \
           ____/_____\__\@  @/___/_____\____
          |             |\../|              |
          |              \VV/               |
          |        ------___-------         |
          |__________Chuta Dragon___________|
           |    /\ /      \\       \ /\    |
           |  /   V        ))       V   \  |
           |/     `       //        '     \|
           `              V                '
        */
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cin>>ara[i];
}

#define eb emplace_back

int main()
{


    fastread();



    ll n,l;


    cin>>n>>l;

    ll sum=0;

    ll ara[n+2],t=0,mn=1000,ans=0;

  for(ll i=1;i<=n;i++)
  {
      ara[i]=i+l-1;
      sum+=ara[i];

      t=abs(ara[i]-0);

      if(t<mn)
      {
          mn=t;

          ans=ara[i];

      }

  }



 //for(ll i=1;i<=n;i++)cout<<ara[i]<<" ";cout<<endl;



 cout<<sum-ans<<endl;











}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    
    vector<vector<int>> v(m);
    REP(i, n) {
        int a, b;
        cin >> a >> b;
        if (a > m) continue;
        v[m-a].push_back(b);
    }
    
    priority_queue<int> q;
    ll ans = 0;
    for (int i = m - 1; i >= 0; i--) {
        for (int x : v[i]) {
            q.push(x);
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 5632
#include<iostream>
#include<vector>
#include<algorithm>
#define  M 1e6
using namespace std;
typedef long long int ll;
vector<ll> x,y;
ll f(int n){
	return n*(n+1)*(n+2)/6;
}
void make(void){
	int i=1;
while(f(i)<M){
x.push_back(f(i));
if(f(i)%2==1){
	y.push_back(f(i));
}
	i++;
}
}
int main(void){
	make();
vector<ll> num(M,6),num2(M,1000000);
for(ll i=0;i<x.size();i++){
num[x[i]]=1;
}
for(ll i=0;i<y.size();i++){
	num2[y[i]]=1;
}
for(ll i=0;i<x.size();i++){
	for(ll j=x[i];j<M;j++){
		num[j]=min(num[j],num[j-x[i]]+1);
	}
}
for(ll i=0;i<y.size();i++){
	for(ll j=y[i];j<M;j++){
		num2[j]=min(num2[j],num2[j-y[i]]+1);
	}
}
int n;

while(1){
	cin>>n;
	if(n==0)break;

	cout<<num[n]<<" "<<num2[n]<<endl;
}
return 0;
}

Measured memory_bytes: 18220
#include<iostream>
using namespace std;
const int nmax=8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
  
  bool all_visited=true;
  for(int i=0;i<N;++i){
    if(visited[i]==false)
    all_visited=false;
  }
  
  if(all_visited){
    return 1;
  }
  
  int ret=0;
  
  for(int i=0;i<N;++i){
    if(graph[v][i]==false) continue;
    if(visited[i]) continue;
    
    visited[i]=true;
    ret+=dfs(i,N,visited);
    visited[i]=false;
  }
  
  return ret;
}

int main(void){
  int N,M;
  cin >> N >> M;
  
  for(int i=0;i<M;++i){
    int A,B;
    cin >> A >> B;
    graph[A-1][B-1]=graph[B-1][A-1]=true;
  }
  
  bool visited[nmax];
  for(int i=0;i<N;++i){
    visited[i]=false;
  }
  visited[0]=true;
  cout << dfs(0,N,visited) << endl;
  return 0;
}

Measured memory_bytes: 256
program main
      implicit none
      integer :: n, cnt, i
      integer(8), allocatable :: a(:)

      read *, n
      allocate( a(n) )
      read *, a

      call quicksort1( a, 1, n )
      cnt = 0
      do i = 1, n-1
        if ( a(i) == a(i+1) ) then
        else
          cnt = cnt + 1
        end if
      end do
      if ( cnt == n - 1 ) then
        print *, 'YES'
      else
        print *, 'NO'
      end if

end program main
recursive subroutine quicksort1(a, first, last)
  implicit none
  integer(8),intent(inout)::a(*)
  integer,intent(in)::first,last
  !
  ! Original
  ! https://gist.github.com/t-nissie/479f0f16966925fa29ea
  !
  integer(8)::x,t
  integer::i,j

  x = a((first+last)/2)
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
     a(i) = a(j)
     a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i-1) call quicksort1(a, first, i-1)
  if (j+1 < last)  call quicksort1(a, j+1, last)

  return
end subroutine quicksort1


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

using namespace std;

const int N = 155;
const long long INF = 2e18 + 5;

long long f[N][N];
int n, a, b, r[N], s[N];

int main() {
  cin >> n >> a >> b;
  for (int i = 1; i <= n; ++i) {
    cin >> r[i] >> s[i];
  }
  for (int i = n; i; --i) {
    s[i] += s[i + 1];
  }
  f[n + 1][0] = -INF;
  for (int i = n; i; --i) {
    for (int j = s[i]; j >= 0; --j) {
      f[i][j] = -INF;
      // eat
      if (s[i] - j + 1 <= s[i + 1]) {
        f[i][j] = 1 - r[i] - f[i + 1][s[i] - j + 1];
      }
      // pass
      if (j <= s[i + 1]) {
        f[i][j] = min(f[i][j], max(1LL, 1 + r[i] + f[i + 1][j]));
      }
    }
  }
  for (int i = s[1]; i >= 0; --i) {
    if (a - b >= f[1][i]) {
      cout << i << " " << s[1] - i << '\n';
      return 0;
    }
  }
  return 0;
}




Measured memory_bytes: 3280
package main

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

func figure(s, p string) bool {
	if strings.Contains(s, p) {
		return true
	}

	for i := 0;; {
		idx := strings.Index(p[i:], string(s[len(s)-1])+string(s[0]))
		if idx == -1 {
			break
		}
		idx += i
		if string(s[len(s)-(idx+1):])+string(s[:len(p)-(idx+1)]) == p {
			return true
		}
		i = idx+1
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	s := scanner.Text()
	scanner.Scan()
	p := scanner.Text()

	fmt.Println(map[bool]string{true:"Yes", false:"No"}[figure(s, p)])
}



Measured memory_bytes: 1124
import sys
# a, b = map(int,input().split())

# n,k = map(int,input().split())
# n = int(input())
n,k,q = map(int,input().split())
whocorrect = [int(input()) for _ in range(q)]
points = [0] * n
for who in whocorrect:
        points[who-1] += 1
answer = list(map(lambda x: 'No' if k <= q-x else 'Yes',points))
for a in answer:
        print(a)


Measured memory_bytes: 9412
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<string>
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int main()
{
	int n;
	cin>>n;
	cout<<(n-1)/2+1<<endl;
	
	
	return 0;
 } 

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const ll INF = 1001001001;
const double pi = acos(-1);

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    while (true)
    {
        if (n == 0)
            break;
        n /= k;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    int diff_a = abs(x - a), diff_b = abs(x - b);
    if(diff_a < diff_b) cout << "A" << endl;
    else cout << "B" << endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int ans[]=new int[3];
		ans[0]=a+b;
		ans[1]=a-b;
		ans[2]=a*b;
	    Arrays.sort(ans);
	    System.out.print(ans[2]);
	}
}


Measured memory_bytes: 21076
#include <iostream>

int main()
{
	int N, T, n[1000], t[1000],min = 1001;
	std::cin >> N >> T;
	for(int i = 1; i <= N; i++)
	{
		std::cin >> n[i] >> t[i];
		if(n[i] < min && t[i] <= T)
		{
			min = n[i];
		} 
	}
	if(min == 1001)
	{
		std::cout << "TLE";
	}else
	{
		std::cout << min;
	}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int nt(int x){
    if(x % 10 == 0) return x;
    else return x+10-x%10;
}

int main(){
    vector<int> p(5);
    rep(i,5) cin >> p[i];
    vector<int> a(5);
    iota(a.begin(), a.end(), 0);
    int ans = 1e9;
    do{
        int cur = 0;
        rep(i,4){
            cur += p[a[i]]; cur = nt(cur);
        }
        cur += p[a[4]];
        ans = min(ans, cur);
    } while(next_permutation(a.begin(), a.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    private static final int INF = (int) 1e9 + 5;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);
        solve3(scanner, writer);
        scanner.close();
        writer.close();
    }

    public static void solve3(Scanner scanner, PrintWriter writer) {
        int n = scanner.nextInt();

        int[][] activities = new int[n][];
        for (int i = 0; i < n; i++) {
            activities[i] = new int[3];
            activities[i][0] = scanner.nextInt();
            activities[i][1] = scanner.nextInt();
            activities[i][2] = scanner.nextInt();
        }

        // dp[i][j] denote max points of day i-th if playing activity j
        int[] dp = new int[3];

        // First day
        dp[0] = activities[0][0];
        dp[1] = activities[0][1];
        dp[2] = activities[0][2];

        for (int i = 1; i < n; i++) {
            int[] new_dp = new int[3];
            for (int j = 0; j < 3; j++) {
                for (int z = 0; z < 3; z++) {
                    if (z != j) {
                        new_dp[j] = Math.max(new_dp[j], dp[z] + activities[i][j]);
                    }
                }
            }

            dp = new_dp;
        }

        int ans = Math.max(dp[0], Math.max(dp[1], dp[2]));
        writer.println(ans);
    }

}


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

#define tt template<typename T> ostream& operator <<(ostream& os, const
#define tuv template<typename U, typename V> ostream& operator<<(ostream& os, const
tt vector<T>& v)            { os << "["; for(auto & x : v) os << " " << x; os << " ]"; return os; }
tt vector<vector<T> >& m)   { for(auto & x : m) { for(auto & y : x) os << y << " "; os << "\n"; } return os; }
tt set<T>& s)               { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt unordered_set<T>& s)     { os << "{"; for(auto & x : s) os << " " << x; os << " }"; return os; }
tt queue<T>& q)             { queue<T> q2(q); while(!q2.empty()) { os << q2.front() << " "; q2.pop(); } return os; }
tt stack<T>& s)             { stack<T> s2(s); while(!s2.empty()) { os << s2.top() << " "; s2.pop(); } return os; }
tuv pair<U,V>& p)           { os << "(" << p.first << "," << p.second << ")"; return os; }
tuv map<U,V>& m)            { os << "{ "; for(auto & x : m) os << x.first << ":" << x.second << " "; os << "}"; return os; }
tuv unordered_map<U,V>& um) { os << "{ "; for(auto & x : um) os << x.first << ":" << x.second << " "; os << "}"; return os; }


int main(int argc, char * argv[])
{
    std::ios_base::sync_with_stdio(false);    
    std::cin.tie(NULL);


    std::vector<int> v(3);
    for(int i = 0; i < 3; ++i) std::cin >> v[i];

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

    if(v[0] == 5 && v[1] == 5 && v[2] == 7)
	std::cout << "YES" << std::endl;
    else
	std::cout << "NO" << std::endl;

    return 0;
}


Measured memory_bytes: 256
#create date: 2020-03-28 21:04

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    k, n = na()
    a = na()
    lmax = a[0] + (k-a[-1])
    for ai, aj in zip(a[0:-1], a[1:]):
        lmax = max(lmax, (aj-ai))
    print(k-lmax)

if __name__ == "__main__":
    main()

Measured memory_bytes: 26060
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007;
const int MAX = 100005;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll a, b;
    cin>>a>>b;
    ll n = b-a;
    n = (n*(n+1))/2;
    cout<<n-b<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
double n,m,x,y,ans;
int main() {
	//freopen("1.txt","r",stdin);
	read(m); read(n); read(x); read(y);
	printf("%.10lf ",n*m*0.5);
	if (x*2==m&&y*2==n) printf("1\n");
	else printf("0\n");
	return 0;
}

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

struct pp{
	char name[10];
	int time;
};

int head=0, tail=0;
struct pp que[100000];


void enqueue(struct pp *x){
	tail++;
	if(tail>100000){
		tail = 0;
	}
	que[tail] = *x;
}


struct pp dequeue(){
	head++;
	if(head>100000){
		head = 0;
	}
	return que[head];
}


int main(){
	int n, q, cnt=0, i, flag=0;
	struct pp temp;

	scanf("%d %d", &n, &q);
	tail = n;
	for(i=1; i<n+1; i++){
		scanf("%s %d", que[i].name, &que[i].time);
	}

	while(flag<n){
		temp = dequeue();
		if(temp.time>q){
			temp.time -= q;
			cnt += q;
			enqueue(&temp);
		}else{
			cnt += temp.time;
			printf("%s %d\n", temp.name, cnt);
			flag++;
		}
	}

	return 0;
}

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

int main()
{
  long n, a, res, t;
  
  while (cin >> n, n){
    res = -100000000;
    t = 0;
    for(int i = 0; i < n; i++){
      cin >> a;
      t = max(t + a, a);
      res = max(res, t);
    }
    cout << res << endl;
  }
}

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


struct SgTree{
private:
	vector<long long> node;
	long long defval;
	int N;
	int n;
public:
	void init(int n, long long defval = INT64_MAX){
		N = 1;
		while(N < n)N<<=1;
		this->n = n;
		this->defval = defval;
		node.assign(N*2-1, defval);
	}
	long long query(int a, int b, int l = 0, int r = -1, int i = 0){
		if(r == -1) r = N;
		if(b <= l || r <= a) return defval;
		if(a <= l && r <= b) return node[i];
		return query(a,b,l,(l+r)/2,i*2+1) + query(a,b,(l+r)/2,r,i*2+2);
	}
	void update(int p, long long v){
		int q = p + N - 1;
		node[q] += v;
		while(q!=0){
			q = (q-1)/2;
			node[q] = node[q*2+1] + node[q*2+2];
		}
	}
	long long get(int p){ return node[p+N-1];}
};


int main(){

	int n, q;
	cin >> n >> q;
	SgTree sg;
	sg.init(n, 0);

	vector<long long> ans;

	int com, arg1, arg2;
	
	for(int i = 0; i < q; i++){
		cin >> com >> arg1 >> arg2;
		if(com == 0){
			sg.update(arg1-1, arg2);
		}
		else if(com == 1){
			ans.push_back(sg.query(arg1-1, arg2));
		}
	}

	for(long long i : ans)
		cout << i << endl;

	return 0;
}



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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int n;
    cin >> n;

    vll a(n);
    rep(i, 0, n) { cin >> a[i]; }

    vector<vll> dp(n, vll(n, 0));

    rep(i, 1, n) {
        rep(j, 0, n - i) {
            ll maxv = LLONG_MAX;
            ll sum = 0;
            rep(k, j, j + i) {
                maxv = min(maxv, dp[j][k] + dp[k + 1][j + i]);
                sum += a[k];
            }
            dp[j][j + i] = maxv + sum + a[j + i];
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {

    int n, q;
    string s;
    cin >> n >> q >> s;

    vector<int> cnt(n);
    REP(i, 1, s.length()){
        if(s[i-1]=='A' && s[i]=='C'){
            cnt[i]++;
        }
        if(i!=n-1)
            cnt[i+1] = cnt[i];
    }
    rep(i, q){
        int l, r;
        cin >> l >> r;
        cout << cnt[r-1] - cnt[l-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408