akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n;
vector<int> v, w;

void solve() {
	int n; cin >> n;
    v.resize(n); w.resize(n);
    rep(i, n) {
        cin >> v[i] >> w[i];
    }
    static int dp[520][100100];
    rep(i, 520) {
        rep(j, 100100) {
            dp[i][j] = 0;
        }
    }
    for(int j = w[0]; j < 100100; ++ j) {
        dp[0][j] = v[0];
    }
    for(int i = 1; i < min(511, n); ++ i) {
        int p = (i - 1) / 2;
        for(int j = 0; j < 100100; ++ j) {
            chmax(dp[i][j], dp[p][j]);
            if(j + w[i] < 100100) chmax(dp[i][j + w[i]], dp[p][j] + v[i]);
        }
    }
    int q; cin >> q;
    rep(i, q) {
        int e, l; cin >> e >> l;
        -- e;
        if(e < 511) {
            cout << dp[e][l] << endl;
            continue;
        }
        vector<int> es;
        int now = e;
        while(now >= 511) {
            es.push_back(now);
            now = (now - 1) / 2;
        }
        int sz = (int)es.size();
        int ans = 0;
        for(int bit = 0; bit < (1<<sz); ++ bit) {
            int sw = 0, sv = 0;
            rep(j, sz) {
                if(bit & (1<<j)) {
                    sw += w[es[j]];
                    sv += v[es[j]];
                }   
            }
            if(sw <= l) {
                chmax(ans, dp[now][l - sw] + sv);
            }
        }
        cout << ans << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 208592
class _Node {
  constructor(key, parent = null, left = null, right = null) {
    this.key = key;
    this.parent = parent;
    this.left = left;
    this.right = right;
  }

  getChildrenNumber() {return Number(this.left !== null) + Number(this.right !== null);}

  isLeftChild() {
    if (this.parent === null) return null;
    return this.parent.left === this;
  }

  getLeftOrRight() {return this.isLeftChild() ? 'left' : 'right';}

  getSuccessor() {
    let n;
    if (this.right !== null) {
      n = this.right;
      while (n.left !== null) n = n.left;
    } else {
      n = this.parent;
      while (!n.isLeftChild && n.parent != null) n = n.parent;
    }
    return n;
  }
}

class BinaryTree {
  constructor() {
    this.root = null;
  }

  static get Node() { return _Node; }

  insert(key) {
    if (this.root === null) {
      this.root = new BinaryTree.Node(key);
      return;
    }
    let x = this.root, y;
    let newNode = new BinaryTree.Node(key);
    while (x !== null) {
      y = x;
      x = x[key < x.key ? 'left' : 'right'];
    }
    newNode.parent = y;
    y[key < y.key ? 'left' : 'right'] = newNode;
  }

  find(key, n = this.root) {
    if (n === null || n.key === key) return n;
    return this.find(key, n[key < n.key ? 'left' : 'right']);
  }

  delete(key) {
    const n = this.find(key);
    const leftOrRight = n.getLeftOrRight();
    switch (n.getChildrenNumber()) {
    case 0:
      n.parent[leftOrRight] = null;
      break;
    case 1:
      n.parent[leftOrRight] = n.left || n.right;
      n.parent[leftOrRight].parent = n.parent;
      break;
    default:
      const skey = n.getSuccessor().key;
      this.delete(skey);
      n.key = skey;
    }
  }

  printByIneorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      innerFunc(n.left);
      str += ` ${n.key}`;
      innerFunc(n.right);
    }
    innerFunc(this.root);
    // console.log(str);
    process.stdout.write(str + '\n');
  }

  printByPreorder() {
    let str = '';
    const innerFunc = (n) => {
      if (n === null) return;
      str += ` ${n.key}`;
      innerFunc(n.left);
      innerFunc(n.right);
    }
    innerFunc(this.root);
    // console.log(str);
    process.stdout.write(str + '\n');
  }

  print() {
    this.printByIneorder();
    this.printByPreorder();
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());

  const tree = new BinaryTree();
  lines.forEach(function(cmd) {
    switch (cmd.charAt(0)) {
    case 'i': tree.insert(Number(cmd.split(' ')[1])); break;
    case 'f': console.log(tree.find(Number(cmd.split(' ')[1])) ? 'yes' : 'no'); break;
    case 'd': tree.delete(Number(cmd.split(' ')[1])); break;
    default: tree.print();
    }
  });
})();



Measured memory_bytes: 203804
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a, b;
	cin >> a >> b;
	if((a % 3) == 0 || (b % 3 == 0) || (a + b) %  3 == 0) {
		cout << "Possible" << endl; 
	} else {
		cout << "Impossible" << endl;
	}
}



Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 998244353;
const long long inf = 1e18;
 
using namespace std;
 
ll MAXN=100001;
ll spf[100001]; 
 
ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 

 
void solve()
{
   	int x , n ;
   	cin>>x>>n ;
   	int p[n ] ;
   	rep(i , n) cin>>p[i] ;
   	set<int>s ;
   	rep(i , n){
   		s.insert(p[i]) ;
   	}
   	if(s.find(x)==s.end()){
   		cout<<x<<endl;
   		return ;
   	}
   	int mi = x-1 ;
   	int ma = x+1 ;
   	while(s.find(mi)!=s.end()){
   		mi--;
   	}
   	while(s.find(ma)!=s.end()){
   		ma++;
   	}
   	if(abs(mi-x)<=abs(ma-x)){
   		cout<<mi<<endl;
   	}
   	else{
   		cout<<ma<<endl;
   	}
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
vector<int> parent;
long score[100000];
void  create(int n)
{
    parent.clear();
    
    for(int i=0;i<n;i++)
    {
        parent.push_back(i);
       
        
    }
    
    
    
}

int find(int x) 
    { 
        
        if (parent[x] != x) { 
  
    
            parent[x] = find(parent[x]); 
  
        } 
  
        return parent[x]; 
    } 
    
void uniono(int x,int y)
{
    
    int i= find(x);
    int u= find(y);
    
if(score[x]>score[y])    
parent[y]=i;
else
parent[x]=u;

}






int main()
{
   int a;
   cin>> a ;
   int p1=a*a;
   int p2=p1*a;
   cout<<(a+p1+p2);
    return 0;
}


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

int main() {
int x;
  for(int i=1;;i++) {
    cin >> x;
    
  if(x==0){
    break;
  
   }
   cout<< "Case "<< i << ": "<<  x  <<endl;
    } 
  return 0;
}


Measured memory_bytes: 3104
x = int(input())
LIMIT = 10 ** 9
lmt = 0

while lmt ** 5 - (lmt - 1) ** 5 <= LIMIT:
    lmt += 1


for a in range(-lmt, lmt + 1):
    for b in range(-lmt, a + 1):
        # print(a, b)
        if a ** 5 - b ** 5 == x:
            print(a, b)
            exit()

Measured memory_bytes: 9164
n,m=map(int, input().split())
a=list(map(int, input().split()))

a_sum = sum(a)

thr = a_sum/(4*m)
cnt = 0
for i in a:
    if i >= thr:
        cnt += 1

if cnt >= m:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 3060
#include <cstdio>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100000;

typedef long long ll;
#define pb push_back

int n, s;
int x[N + 5], p[N + 5];

int main() {
#ifdef Wearry 
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%d%d", &n, &s);
    for(int i = 1; i <= n; ++i) {
        scanf("%d%d", x + i, p + i);
    }

    vector<int> res;
    int l = 1, r = n;
    ll tl = 0, tr = 0;

    while(l <= n && x[l] < s && r >= 1 && x[r] > s) {
        if(tl + p[l] >= tr + p[r]) {
            tl += tr + p[r];
            tr = 0;
            res.pb(r --);
        } else {
            tr += tl + p[l];
            tl = 0;
            res.pb(l ++);
        }
    }

    while(l <= n && x[l] < s) res.pb(l ++);
    while(r >= 1 && x[r] > s) res.pb(r --);

    ll ans = 0;
    for(int i = (int) res.size() - 1; i >= 0; --i) {
        ans += abs(s - x[res[i]]);
        s = x[res[i]];
    }
    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2> bool chmin(T1 &l, const T2 &r);
template <class T1, class T2> bool chmax(T1 &l, const T2 &r);
template <class T1, class T2> void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N, std::vector<long long> A, std::vector<long long> B) {
  map<int, int> AM, BM;
  rep(i, N) {
    AM[A[i]]++;
    BM[B[i]]++;
  }
  bool ok = true;
  for (auto s : AM) {
    int l = s.first;
    int sz = s.second;
    if (N - BM[l] >= sz) {

    } else {
      ok = false;
    }
  }
  if (!ok) {
    cout << "No" << endl;
    return;
  }
  cout << "Yes" << endl;
  std::map<int, int> match;
  vector<bool> used(N);
  std::vector<int> ans = B;
  reverse(ans.begin(), ans.end());
  int end = N - 1;
  int start = 0;
  for (int i = 0; i < N; i++) {
    if (ans[i] == A[i]) {
      if (ans[start] != A[i] && ans[i] != A[start]) {
        swap(ans[start], ans[i]);
        start++;
      } else if (ans[end] != A[i] && ans[i] != A[end]) {
        swap(ans[i], ans[end]);
        end--;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == A[i]) {
    }
  }

  for (auto s : ans) {
    cout << s << " ";
  }
}

signed main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  std::vector<long long> B(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &B[i]);
  }
  solve(N, std::move(A), std::move(B));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2> bool chmin(T1 &l, const T2 &r) {
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2> bool chmax(T1 &l, const T2 &r) {
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2> void vadd(vector<T1> &v, T2 x) {
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 32920
<?php
//Request Question
function getq($get_word=null){
	if($get_word===null){
		return str_replace("\n","",fgets(STDIN));
	}else if($get_word===1){
		return explode(" ",str_replace("\n","",fgets(STDIN)));
	}
}

/*		START		*/
$humans=getq();
$temp=getq(1);
$days=$temp[0];
$after_choco=$temp[1];
$temp=null;
$doyouwant=array();
for ($i=0; $i < $humans; $i++) { 
	$doyouwant[$i]=getq();
}
$ans=$humans;
for ($i=1; $i < $days; $i++) { 
	for ($x=0; $x < $humans; $x++) { 
		if($i%$doyouwant[$x]==0){
			$ans++;
		}
	}
}
echo $ans+$after_choco."\n";
?>

Measured memory_bytes: 4604
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++) cin >> d[i];
  sort(d.begin(), d.end());
  cout << d[n/2] - d[n/2 -1] << endl;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N):
    return -(-N//2)


def main():
    N = read_int()
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7996
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<array>
#include<cstring>
#include<numeric>
#include<string>
#include<set>
#include<cstdio>
#include<cmath>
#include<unordered_map>
#include<bitset>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    ll n;
    cin>>n;
    vector<char> x;
    int i=1;
    while(n){
        n--;
        x.push_back(n%26 + 'a');
        n/=26;
    }
    for(int i=x.size()-1; i>=0; i--){
        cout<<x[i];
    }
    cout<<"\n";
    return 0;
}


Measured memory_bytes: 3624
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define read(a) scanf("%d", &a)
#define readl(a) scanf("%lld", &a)
#define reads(a) scanf("%s", a)
#define readc(a) scanf("%c", &a)
#define debug(a, b) printf("%s = %d\n", a, b)
#define debug1(a, i, b) printf("%s[%d] = %d", a, i, b)
#define show(a) putchar(a)
#define pb push_back
#define mk make_pair
#define _rand mt19937 RAND(time(0))
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define mem(a) memset(a, 0, sizeof(a))
#define Buff ios::sync_with_stdio(false)
typedef long long ll;
typedef long long LL;
using namespace std;
const int INF = 1e9 + 7;
const int N = 2e5 + 7;
const int M = 5e6 + 7;
set<int> s;
signed main()
{
    Buff;
    int n;
    cin >> n;
    int Ans = 1;
    for(int i = 1, x; i <= n; i++)
    {
        cin >> x;
        if(x % 2 == 0 && x % 5 != 0 && x % 3 != 0) Ans = 0;
    }
    if(Ans) cout << "APPROVED\n";
    else    cout << "DENIED\n";
    return 0;
}
/**
    A
**/


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

int main(){
  int n; cin >> n;
  if(n == 0){
      cout << 0 << '\n';
      return 0;
  }
  int base = -2;
  string ans;
  while(n){
    int r = n%base;
    n = n/base;
    if(r < 0) n++;
    if(r < 0) r = r*(-1);
    char x = r + '0';
    ans = x + ans;
    
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;
typedef pair<string, string> P;

int s(int n);
int main(int argc, char *argv[])
{
  int n, sn;
  cin >> n;
  sn = s(n);
  if(n%sn==0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

int s(int n){
  if(n/10==0){
    return n;
  }else{
    return s(n/10)+n%10;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll N;
  cin >> N;
  ll ans=0;
  for(int i=1;i<=N;++i){
    if(i%3==0 | i%5==0) continue;
    ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include<complex>
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
typedef long double ld;
typedef complex<ld> P;
#define X real
#define Y imag
vector<P> data;

namespace std{
  bool operator<(P a,P b){
    return a.X()!=b.X()? a.X()<b.X():a.Y()<b.Y(); 
  }
}

double cross(P a,P b){
  return imag(conj(a)*b);
}

double dot(P a,P b){
  return real(conj(a)*b);
}

int ccw(P a,P b,P c){
  b-=a;c-=a;
  if(cross(b,c)>0)return 1;     //counter clockwise
  if(cross(b,c)<0)return -1;    //clockwise
  if(dot(b,c)<0)return 2;       //c--a--b on line
  if(norm(b)<norm(c))return -2; //a--b--c on line
  return 0;
}

vector<P> convex_hull(vector<P> ps){
  sort(ps.begin(),ps.end());
  vector<P> ch(ps.size()*2);
  int k=0;
  for(int i=0;i<ps.size();ch[k++]=ps[i++]){
    while(k>=2 && ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
  }
  for(int i=ps.size()-2,t=k+1;i>=0;ch[k++]=ps[i--]){
    while(k>=t&&ccw(ch[k-2],ch[k-1],ps[i])<=0)--k;
  }
  ch.resize(k-1);
  return ch;
}

int solve(){
  vector<P> res = convex_hull(data);
  return res.size();
}


int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    data.clear();
    for(int i=0;i<n;i++){
      ld a,b;
      char c;
      cin>>a>>c>>b;
      data.push_back(P(a,b));
    }
    cout<<n-solve()<<endl;
  }
}

Measured memory_bytes: 1276
n = int(input())
st = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
s = input()
for i in range(len(s)):
    a = (st.index(s[i]) + n) % 26
    print(st[a],end="")

Measured memory_bytes: 4468
import platform
ver = platform.python_version_tuple()
if int(ver[1]) < 5:
    from fractions import gcd
else:
    from math import gcd

from sys import stdin
from bisect import bisect

def main():
    N, M = map(int, input().split())
    S = input()
    T = input()

    L = lcm(N, M)
    s = [i * (L // N) + 1 for i in range(N)]
    t = [i * (L // M) + 1 for i in range(M)]
    for i, x in enumerate(s):
        n = bisect(t, x)
        if t[n-1] == x:
            if T[n-1] != S[i]:
                print(-1)
                return
    print(L)

input = lambda: stdin.readline().rstrip()
lcm = lambda x, y: x * y // gcd(x, y)
main()


Measured memory_bytes: 13376
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=1e9+7;
const ll ms=1e6+5;
const ll inf=1e17;


ll ar[ms];


int main()
{
    idfc;

    ll n,m;
    cin>>n>>m;
    int i;
    ll ss=0;
    ll a=0;
    ll b=0;
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
        ss+=ar[i];
        ss+=modo;
        ss%=modo;
    }

    for(i=1;i<=n;i++)
    {
        ss=(ss+modo-ar[i])%modo;
        a+=(ss+modo-((ar[i]*(n-i))%modo));
        a%=modo;
    }
    //cout<<a<<"\n";
    ss=0;
    for(i=1;i<=m;i++)
    {
        cin>>ar[i];
        ss+=ar[i];
        ss+=modo;
        ss%=modo;
    }
    for(i=1;i<=m;i++)
    {
        ss=(ss+modo-ar[i])%modo;
        b+=(ss+modo-((ar[i]*(m-i))%modo));
        b%=modo;
    }
    cout<<(a*b)%modo;
    return 0;
}

Measured memory_bytes: 4416
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  string s, t;
  cin >> s >> t;
  bool answerable = false;
  for(int i = s.length() - 1; i >= 0; --i){
    if(i + t.length() - 1 >= s.length())  continue;
    bool ok = true;
    string tmp = s;
    for(int j = t.length() - 1; j >= 0; --j){
      if(s[i + j] == '?' || t[j] == s[i + j]) tmp[i + j] = t[j];
      else ok = false;
    }
    if(ok){
      s = tmp;
      answerable = true;
      break;
    }
  }
  if(answerable){
    rep(i, s.length()){
      if(s[i] == '?') s[i] = 'a'; 
    }
    cout << s << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)

int main() {
    int n;
    cin >> n;
    const ll INF = 100000000;
    vector<int> a;
    a.push_back(1);
    

    int tmp = 6;
    while(tmp <= n) {
        a.push_back(tmp);
        tmp*=6;
    }
    tmp = 9;
    while(tmp <= n) {
        a.push_back(tmp);
        tmp*=9;
    }

    vector<vector<ll>> dp(a.size()+1, vector<ll>(100010, INF));
    dp[0][0] = 0;

    rep(i, 0, a.size()) {
        int power = 1;
        int num = a[i];
        rep(j, 0, n+1) {
            if(j-a[i] > -1) {
                dp[i+1][j] = min({dp[i+1][j], dp[i][j], dp[i+1][j-a[i]]+1});
            }
            else {
                dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
            }
        }
    }
    cout << dp[a.size()][n] << endl;
    return 0;
}

Measured memory_bytes: 11264
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String args[]) {
		FastScanner in=new FastScanner();
		StringBuilder sb=new StringBuilder(in.next());
		int n=sb.length();
		if(sb.charAt(n-1)=='s') {
			sb.append('e');
		}
		sb.append('s');
		System.out.println(new String(sb));
	}

	///////////////////////////
	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			while (!st.hasMoreTokens())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

		int[] nextArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

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


Measured memory_bytes: 32708
from operator import itemgetter
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)] 

ab.sort(key=itemgetter(1), reverse=True)

amax = max([i[0] for i in ab]) 
num = 0
dmg = 0
jdg = False

for a, b in ab:
    if b > amax:
        num += 1
        dmg += b
        if dmg >= H:
            jdg = True
            break
if not jdg:
    num += math.ceil((H - dmg) / amax)
print(num)

Measured memory_bytes: 28916
#include <bits/stdc++.h>
 
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define fff(i,a,b) for(int (i)=(a);(i)<=(b);i++)
#define pb push_back
#define len(a) (a).length()
#define all(a) (a).begin(),(a).end()
#define sz(a) (a).size()
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long ,long long > pll;
typedef unsigned long long ull;
typedef long double ld;
 
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t=1;
	int x,n;
	cin>>x>>n;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int r=1000;
	int xx=0;
	for(int i=-100;i<=101;i++)
	{
		bool ima=false;
		for(int j=0;j<n;j++) if(a[j]==i) ima=true;
		if(!ima && abs(x-i)<r)
		{
			xx=i;
			r=abs(x-i);
		} 
	}
	cout<<xx<<endl;
	return 0;
}

Measured memory_bytes: 3532
N = int(input())
L = list(map(int, input().split()))
 
L.sort()
count = 0
 
for i in reversed(range(N)):
  kmin = 0
  for j in reversed(range(i)):
    for k in range(kmin,j):
      if L[j] + L[k] > L[i]:
        count += j - k
        kmin = k
        break
        
print(count)

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

int main() {
    int n, m;
    cin >> n >> m;
    
    map<int, bool> mp;
    for (int i = 1; i <= n; i++)
    {
        mp[i] = false;
    }
    
    int AC = 0, WA = 0;
    vector<int> pena(n);
    for (int i = 0; i < m; i++)
    {
        int p;
        string s;
        cin >> p >> s;
        if (mp[p] == false and s == "AC") {
            AC++;
            mp[p] = true;
        }
        else if (mp[p] == false and s == "WA") {
            pena[p-1]++;
        }
    }
    for (int i = 0; i < n; i++)
    {
        if (mp[i+1] == true) {
            WA += pena[i];
        }
    }
    
    cout << AC << " " << WA << endl;
    
    return 0;
}

Measured memory_bytes: 5376
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;
int main(){
  long n,ii;
  vector<long> a;
  cin >> n;
  a.resize(n);

  for(ii=0;ii<n;ii++){
	cin >> a[ii];
  }

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

  //cout << a[0] << " " << a[a.size()-1] << endl;
  cout << a[a.size()-1] - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<queue>
#include<stack>
#include<numeric>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define MEM(a,b) memset(a,b,sizeof(a))

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int main() {
	IOS;
	string s, t;
	bool exist;
	cin >> s >> t;
	if (s.size() < t.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	reverse(s.begin(), s.end());
	reverse(t.begin(), t.end());
	int T = s.size() - t.size() + 1;
	bool tmp;
	REP(i, T) {
		tmp = true;
		REP(j, t.size())if (!(s[j + i] == t[j] || s[j + i] == '?'))tmp = false;
		if (tmp) {
			s.replace(i,t.size(),t);
			break;
		}
		if (i == T - 1 && !tmp) {
			cout << "UNRESTORABLE" << endl;
			return 0;
		}
	}
	reverse(s.begin(), s.end());
	REP(i, s.size()) {
		if (s[i] == '?')s[i] = 'a';
	}
	cout << s << endl;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

template<typename T, bool directed, T inf> class FordFulkerson {
private:
    struct Edge {
        int to; T cap; int rev;
        Edge(int to, T cap, int rev) : to(to), cap(cap), rev(rev) {}
    };

    vector<vector<Edge>> G;
    vector<bool> used;

    void init(int n) {
        G = vector<vector<Edge>>(n);
        used = vector<bool>(n);
    }

    T dfs(int s, int t, ll f) {
        if (s == t) return f;

        used[s] = true;
        REP (i, G[s].size()) {
            Edge &e = G[s][i];
            if (!used[e.to] && e.cap > T(0)) {
                T d = dfs(e.to, t, min(f, e.cap));
                if (d == T(0)) continue;
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }

        return T(0);
    }

public:
    FordFulkerson() {}
    FordFulkerson(int n) { init(n); }

    void add(int from, int to, T cap) {
        if (!cap) return;
        G[from].push_back(Edge(to, cap, G[to].size()));
        G[to].push_back(Edge(from, (directed ? 0 : cap), G[from].size()-1));
    }

    T solve(int s, int t) {
        T ret(0);
        while (1) {
            fill(ALL(used), false);
            T f = dfs(s, t, inf);
            if (f == 0) return ret;
            ret += f;
        }
    }
};

const int MAX = 111;
const ll INF = 1ll<<62;

int H, W;
string A[MAX];

int solve() {
    FordFulkerson<ll, false, INF> ford(H+W+2);
    int S = H+W, T = H+W+1;
    REP (h, H) REP (w, W) {
        if (A[h][w] == 'S') {
            ford.add(S, h, INF);
            ford.add(S, w+H, INF);
        } else if (A[h][w] == 'T') {
            ford.add(h, T, INF);
            ford.add(w+H, T, INF);
        } else if (A[h][w] == 'o') {
            ford.add(h, w+H, 1);
        }
    }

    ll ret = ford.solve(S, T);
    if (ret >= INF) ret = -1;
    return ret;
}

int main() {
    cin >> H >> W;
    REP (i, H) cin >> A[i];
    cout << solve() << endl;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N;
  cin >> N;
  cout << N * N * N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define P pair<int,int>
struct edge{int to,cost;};
using namespace std;


class CompareDist
{
public:
    bool operator()(pair<int,int> n1,pair<int,int> n2) {
        return n1.second>n2.second;
    }
};

int V;
vector<vector<edge>> G;
vector<int> d;

void dijkstra(int s){
    priority_queue<P,vector<P>,CompareDist> q;
    //fill(d,d+V,INT_MAX);
    d=vector<int>(V,INT_MAX);
    d[s]=0;
    q.push(P(0,s));
    
    while(!q.empty()){
        P p=q.top();q.pop();
        int v=p.first;
        if(d[v]<p.second)continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                q.push(P(e.to,d[e.to]));
            }
        }
    }
}
int main(void){
    int n,in,t,c;
    cin>>n;
    V=n;
    G.resize(n);
    d.resize(n);
    for(int i=0;i<n;i++){
        cin>>in;
        int node=in;
        cin>>in;
        for(int j=0;j<in;j++){
            cin>>t>>c;
            G[node].emplace_back((edge){t,c});
        }
        
    }
    dijkstra(0);
    for(int i=0;i<d.size();i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}



Measured memory_bytes: 3176
#include <cstdio>
#include <string.h>

using namespace std;

namespace {

const size_t kHashSize = 244140624;

class Dictionary {
 public:
  Dictionary() : table_(new int[kHashSize]) {
    ps_[0] = 1;
    for (int i = 1; i < 12; ++i) {
      ps_[i] = 5 * ps_[i - 1];
    }
  }

  ~Dictionary() { delete[] table_; }

  void insert(const char* k, size_t n) {
    const size_t i = Encode(k, n);
    table_[i] = 1;
  }

  bool find(const char* k, size_t n) const {
    return table_[Encode(k, n)] > 0;
  }

 private:
  static int Id(char c) {
      switch (c) {
        case 'A':
          return 1;
        case 'C':
          return 2;
        case 'G':
          return 3;
        case 'T':
          return 4;
      }
      // should not reach here.
      return 0;
  }

  size_t Encode(const char* k, size_t n) const {
    size_t h = 0;
    for (size_t i = 0; i < n; ++i) {
      h += ps_[i] * Id(k[i]);
    }
    return h;
  }

  int ps_[12];
  int* table_;
};

} // namespace

int main() {
  int n;
  scanf("%d", &n);

  Dictionary d;
  char op[7];
  char str[13];
  for (int i = 0; i < n; ++i) {
    scanf("%s %s", op, str);
    const char c = op[0];
    const size_t len = strnlen(str, 13);
    if (c == 'i') {
      d.insert(str, len);
      continue;
    }

    if (d.find(str, len)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

Measured memory_bytes: 40420
s = input()
A = s[0]
B = s[1]
C = s[2]
D = s[3]

m = ["+","-"]

for i in m:
    for j in m:
        for k in m:
            a = eval(A+i+B+j+C+k+D)
            if a == 7:
                print(A+i+B+j+C+k+D+"=7")
                exit()

print()

Measured memory_bytes: 3060
program bbb
implicit none

integer :: n, m, c, i, j, res1, res2
integer,allocatable,dimension(:,:) :: a
integer,allocatable,dimension(:) :: b

read*, n, m, c
allocate(a(m,n),b(m))

read*, b
do i=1,n
read*, a(:,i)
end do

res1=0

do i=1,n
 res2=0
 do j=1,m
 res2=res2+a(j,i)*b(j)
 end do
 if(res2+c>0) res1=res1+1
end do

write(*,'(i0)') res1

end program

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

#define int long long
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N=1e5+5;

 
int solve(int n)
{
    return n * (n-1)/2;
}
 
int32_t main()
{
	IOS;
	int n;
	cin>>n;
	cout<<solve(n)<<endl;
	return 0;
}

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

int main() {

  int N;
  cin >> N;
  
  int P = 0, W = 0, G = 0, Y = 0; 
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    
    if (S == "P") 
      P++;
    else if (S == "W")
      W++;
    else if (S == "G")
      G++;
    else if (S == "Y")
      Y++;
    
  }
  
  if (Y >= 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;

}


Measured memory_bytes: 256
//http://kmjp.hatenablog.jp/entry/2017/10/23/0900
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <chrono>
#include <random>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<i64, i64>;

int ans[501][501];

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    
    if (d % 2) {
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                ans[y][x] = (y + x) % 2;
            }
        }
    } else if (d % 4 == 2) {
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                ans[y][x] = (y % 2 * 2) + (y / 2 + x / 2) % 2;
            }
        }
    } else {
        for (int y = 0; y < h; y++) {
            for (int x = 0; x < w; x++) {
                int dy = y + x + 1000;
                int dx = y - x + 1000;
                ans[y][x] = dy / d % 2 * 2 + dx / d % 2;
                if ((y + x) % 2) ans[y][x] ^= 3;
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cout << "RGBY"s[ans[i][j]];
        }
        cout << endl;
    }
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005]={0};
int main()
{
    int n;
    cin>>n;
    int maxa=0;
    for(int i=0;i<n;i++)
    {
        int c;
        cin>>c;
        if(i==0&&c!=0)
        {
            cout<<"0";
            return 0;
        }
        a[c]++;
        maxa=max(c,maxa);
    }

    if(a[0]!=1)
    {
        cout<<"0";
        return 0;
    }
    long long ans=1;
    for(int i=1;i<=maxa;i++)
    {
        //cout<<a[i]<<'\n';

        if(a[i]==0)
        {
            cout<<"0";
            return 0;
        }
        for(int j=0;j<a[i];j++)
            ans=(ans*a[i-1])%998244353;
        //cout<<ans<<'\n';
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
int n,a[MAXN],now,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		if(a[i]==now+1)
			now++;
	if(now==0)
		cout<<-1;
	else
		cout<<n-now;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pii;

const long double pi = acos(-1);
const double PI = acos(-1.);

#define MOD 1000000007
const int N = 2e5 + 5;
const int K = 1e5 + 5;
const int Ai = 1e6 + 6;
const int LOGN = 30;

ll tree[4*N];

void update(int x, ll v, int node = 1, int st = 0, int en = N - 1) {
    if(st > x || en < x)
        return;
    if(x == st && en == x) {
        tree[node] = v;
        return;
    }

    int mid = (st + en) / 2;
    update(x, v, 2*node, st, mid);
    update(x, v, 2*node + 1, mid + 1, en);

    tree[node] = max(tree[2*node], tree[2*node + 1]);
}

ll query(int l, int r, int node = 1, int st = 0, int en = N - 1) {
    if(st > r || en < l)
        return 0;
    if(st >= l && en <= r)
        return tree[node];

    int mid = (st + en) / 2;

    ll res1 = query(l, r, 2*node, st, mid);
    ll res2 = query(l, r, 2*node + 1, mid + 1, en);

    return max(res1, res2);
}

ll h[N], b[N];
ll dp[N];

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

    int n; cin >> n;

    for(int i = 0; i < n; i++)
        cin >> h[i];
    for(int i = 0; i < n; i++)
        cin >> b[i];

    dp[0] = b[0];
    update(h[0], dp[0]);

    for(int i = 1; i < n; i++) {
        ll res = query(1, h[i]);
//        cout << i+1 << " " << res << "\n";

        dp[i] = res + b[i];
        update(h[i], dp[i]);
    }

    ll res = 0;
    for(int i = 0; i < n; i++)
        res = max(res, dp[i]);

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 10496
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;

char ss[4][10] = {"AC", "WA", "TLE", "RE"};
int ans[4];
int main(){
	int n;
	memset(ans, 0,sizeof(ans));
	cin>>n;
	while(n--){
		char s[10];
		scanf("%s", s);
		for(int i = 0; i < 4; i++){
			if(strcmp(ss[i], s) == 0){
				ans[i]++;
				break;
			}
		}		
	}
	
	for(int i = 0; i < 4; i++){
		cout<<ss[i]<<" x "<<ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3260
A, B, C, X, Y = map(int, input().split())

values = []

values.append(A*X + B*Y)

if X >= Y:
    values.append(2*C*X)
    values.append(2*C*Y + A*(X-Y))
else:
    values.append(2*C*Y)
    values.append(2*C*X + B*(Y-X))

print(min(values))


Measured memory_bytes: 9048
#include <stdio.h>

int main()
{
	char a[3][3];
	int i,j;
	for(i=0;i<3;i++)
	{ 
		for(j=0;j<3;j++)
			scanf("%c",&a[i][j]);
		getchar(); 
	} 
	for(i=0;i<3;i++)
		printf("%c",a[i][i]);
	
}

Measured memory_bytes: 128
import math

while True:
    X = input().split()
    a = int(X[0])
    op = X[1]
    b = int(X[2])

    if op == "?":
        break

    if op == "+":
      print(a + b)
    elif op == "-":
      print(a - b)
    elif op == "*":
      print(a * b)
    elif op == "/":
      print(math.floor(a / b))


Measured memory_bytes: 5660
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define inf (1LL << 55)
const int maxnodes=1005;
#define ll long long
#define N 1000001
#define EPS 0.01
int f[N];
int dp[N];
int32_t main()
{
    IOS;
    
    memset(f,-1,sizeof(f));
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> v;
	for(int i = 0;i < n;i++)
		cin >> a[i];
	for(int i = 0;i < n;i++)
	{
		int j = i;
		for(;j < n;j++)
		{
			if(a[i] != a[j])
				break;;
		}
		v.push_back(a[i]);
		i = j - 1;
	}
	n = v.size();
	dp[0] = 1;
	for(int i = 0;i < n;i++)
	{

		if(i == 0)
		{
			dp[i] = 1;

		}
		else
		{
			if(f[v[i]] != -1)
				dp[i] = (dp[i-1] + dp[f[v[i]]])%mod;
			else
				dp[i] = dp[i-1];
		}
		f[v[i]] = i;
	}
	cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 14576
N = int(input())
S = list(map(int, input().split()))
S.sort(reverse = True)
ans = 'Yes'
used = set([0])
L = [S[0]]
for k in range(1, N+1):
    cnt = 0
    for i in range(2**N):
        if i in used:
            continue
        if L[cnt] > S[i]:
            used.add(i)
            cnt += 1
            L.append(S[i])
        if cnt == (2**(k-1)):
            break
    else:
        ans = 'No'
        break
    L.sort(reverse = True)
    continue
print(ans)

Measured memory_bytes: 120136
#include <iostream>
#include <cstring>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin>>a[i];
    }
    int max=-1;
    int min=1002;
    for(int i=0;i<N;i++){
        if(a[i]>max) max=a[i];
        if(a[i]<min) min=a[i];
    }
    cout<<max-min;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> edge;

ll n;
//string ss[1000000];
//char ss[1000000][12];
string ss[1000000];
ll checker[1000000][26];

bool comp2(const string& left, const string& right) {
    return left < right;
}

int main(){
    ll res=0;
    ll cnt=0;
    cin >> n;
    for(int i=0; i<n; i++) cin >> ss[i];
    //for(int i=0; i<n; i++) sort(&ss[i][0], &ss[i][10]);
    for(int i=0; i<n; i++) sort(ss[i].begin(), ss[i].end());

    sort(ss, ss+n, comp2);
    cerr << endl;
    cerr << ss[0] << endl;
    for(int i=1; i<n; i++){
        cerr << ss[i] << endl;
        if( ss[i-1]==ss[i] ){
            cnt++;
            res += cnt;
        }else{
            cnt = 0;
        }
        cerr << cnt << endl;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 14720
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int gcd(int, int);
int main(void) {
	int x, y, z;
	int xa, xm, ya, ym, za, zm;
	long a, b, c,i;
	long long cnt;
	for (; fscanf(stdin, "%d%d%d%d%d%d", &xa, &xm, &ya, &ym, &za, &zm); P(lld, cnt)) {
		if (!xa||!xm||!ya||!ym||!za||!zm) break;
		for (i = xa, a = 1; i != 1; i = (xa*i) % xm, a++);
		for (i = ya, b = 1; i != 1; i = (ya*i) % ym, b++);
		for (i = za, c = 1; i != 1; i = (za*i) % zm, c++);
		cnt = a*b / gcd(a, b);
		cnt = cnt*c / gcd(cnt, c);
	}
	return 0;
}

int gcd(int a, int b){
	int c;
	while ((c = a%b) != 0) {
		a = b;
		b = c;
	}
	return b;
}

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

struct score {
    int id;
    int solve;
    int penalty;

    score(){}
    score(int a, int b, int c): id(a), solve(b), penalty(c) {} ~score(){}

    bool operator< (const score& o) const {
        if(solve != o.solve) return solve > o.solve;
        if(penalty != o.penalty) return penalty < o.penalty;
        return id < o.id;
    }
};

int main() {
    int T; // number of teams
    int P; // number of problems
    int R; // number of records
    while(true) {
        cin >> T >> P >> R;
        if(T == 0) break;
        int solve[50][10];
        int penalty[50][10];

        for(int i = 0; i < T; ++i) {
            fill(solve[i], solve[i] + P, 0);
            fill(penalty[i], penalty[i] + P, 0);
        }

        for(int i = 0; i < R; ++i) {
            int tid, pid, time; string mes;
            cin >> tid >> pid >> time >> mes; 
            --tid; --pid;
            if(mes == "CORRECT") {
                solve[tid][pid] = time;
            } else {
                ++penalty[tid][pid];
            }
        }

        vector<score> scores(T);

        for(int i = 0; i < T; ++i) {
            int slv = 0, pnl = 0;
            for(int j = 0; j < P; ++j) {
                if(solve[i][j] > 0) {
                    ++slv;
                    pnl += 1200 * penalty[i][j] + solve[i][j];
                }
            }
            scores[i] = score(i + 1, slv, pnl);
        }

        sort(begin(scores), end(scores));

        for(score s: scores) {
            cout << s.id << ' ' << s.solve << ' ' << s.penalty << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1224
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

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

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

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

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

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};


int main() {
    ll A, B; cin >> A >> B;
    ll ans = lcm(A, B);
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1)%LEN;  
}

P dequeue(){
  P x = Q[head];
  head = (head + 1)%LEN;
  return x;
}

int min(int a,int b){
  return a < b ? a :b;
}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

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

  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0)
      enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  
      
  return 0;
}



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

int mod = 1000000007;

int main()
{
    string S;
    cin >> S;
    int size = S.size();
    int ans = 0;
    for (int i = 0; i < size / 2; i++)
        if (S[i] != S[size - i - 1])
            ans++;
    cout << ans;
}

Measured memory_bytes: 256