akhauriyash/Code-Regression huggingface dataset:
//Dragon_warrior7(IITK)
//#pragma GCC optimize("O0") 
//#pragma GCC optimize ("Ofast")
//#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
//#define lll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
//#define ull unsigned ll
#define vll vector<ll>
#define vpll vector<pll> 
#define rub cerr << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void read(vector<ll> &v)
{for (int i = 0; i < v.size(); i++)cin>>v[i];}
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll int gcd(ll int a ,ll int b)
{if(b==0) return a;a%=b;return gcd(b,a);}
void storepowers(int n,vector<int> &a);
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{//deb(test);
cin>>n>>m;
ll val[n+1];
for(int i=1;i<=n;i++)
cin>>val[i];
ll mxval[n+1]={0};
while(m--)
{
    cin>>a>>b;
    mxval[a]=max(mxval[a],val[b]);
    mxval[b]=max(mxval[b],val[a]);
}
int cnt=0;
for(int i=1;i<=n;i++)
{
    if(mxval[i]<val[i])
    cnt++;
}
cout<<cnt;
return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}
void storepowers(int n,vector<int> &a)
{
    a.resize(n+1);
    a[0]=1;
    for(int i=1;i<=n;i++)
    a[i]=a[i-1]*2;
    return ;
}


Measured memory_bytes: 5168
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


int main() {
	int H, W, N;
	cin >> H >> W >> N;
	map<P, int> m;
	rep(i, N) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		rep(j, 3)rep(k, 3) {
			int y = a + j - 1, x = b + k - 1;
			if (y < 0 || y >= H || x < 0 || x >= W)continue;
			if (m.find(mp(y, x)) == m.end()) {
				m[mp(y, x)] = 1;
			}
			else {
				m[mp(y, x)]++;
			}
		}
	}
	vll num(10, 0);
	int sum = 0;
	repi(itr, m) {
		int y = itr->first.first, x = itr->first.second;
		if (y == 0 || y == H - 1 || x == 0 || x == W - 1)continue;
		num[itr->second]++;
		sum++;
	}
	num[0] = (ll)(H - 2)*(W - 2) - sum;
	rep(i, 10) {
		cout << num[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 56448
#include<cstdio>
#include<cstring>
using namespace std;
char a[100008];
int main()
{
	scanf("%s",a);
	int t=strlen(a);
	int i,j,sum=0;
	for(i=0;i<t;i++)
	{
	if(a[i]!=a[i+1])
	break;
	}
	if(i==t-1)
	{
	printf("0");
	return 0;
	}
	for(j=i;j<t-1;j++)
	{
	if(a[j]!=a[j+1])
	sum++;	
	}
	printf("%d\n",sum);
	
}

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

int main()
{
int h, w;
std::cin >> h >> w;
std::vector<std::string> route;

for(int i = 0; i < h + 2; i++){
    if(i == 0 || i == h + 1){
        std::string temp = "";
        for(int i = 0; i < w + 2; i++){
            temp = temp + ".";
        } 
        route.push_back(temp);
        continue;
    }
    std::string str;
    std::string base = ".";
    std::cin >> str;
    str = str + base;
    base = base + str;
    route.push_back(base);
}
int flag = 0;
for(int i = 1; i < h + 1; i++){
    for(int j = 1; j < w + 1; j++){
        if((route[i - 1][j] == '#') && (route[i][j - 1] == '#')){
            flag = 1;
            break;
        }
    }
    if(flag == 1){
        break;
    }
}
if(flag == 0){
    std::cout << "Possible" << std::endl;
} else {
    std::cout << "Impossible" << std::endl;
}

return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BMultiplication2 solver = new BMultiplication2();
        solver.solve(1, in, out);
        out.close();
    }

    static class BMultiplication2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long[] num = new long[n];
            for (int i = 0; i < n; i++) {
                num[i] = in.nextLong();
            }
            Arrays.sort(num);
            if (num[0] == 0) {
                out.println(0);
                return;
            }

            long ans = 1;
            for (int i = 0; i < n; i++) {
                if (1000000000000000000L / ans < num[i]) {
                    out.println(-1);
                    return;
                }
                ans *= num[i];
                if (ans > 1000000000000000000L || ans < 0) {
                    out.println(-1);
                    return;
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 61684
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;

int main(void) {
        const int AMAX = 200000;
        int N, K;
        cin >> N >> K;

        vector<int> a(AMAX + 1);
        rep(i,N) {
                int x;
                cin >> x;
                a[x]++;
        }

        sort(a.begin(),a.end(),greater<int>());
        long cnt = 0;
        REP(i, K, N) cnt+=a[i];
        cout << cnt <<endl;
        return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define inf 1000000000
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define rng_23 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef set<int> si;
typedef multiset<int> msi;
typedef map<int,int> mii;
int main()
{
    int i;
    int n,m;
    int ara[1000];
    cin>>n>>m;
    int sum=0;
    for(i=0;i<n;i++){
        cin>>ara[i];
        sum+=ara[i];
    }
    int cnt=0;
    for(i=0;i<n;i++){
        if(ara[i]*4*m>=sum)
            cnt++;
    }
    if(cnt>=m)
        cout<<"Yes";
    else
        cout<<"No";
}


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

ll f(int n){
    ll m=1;
    rep(i,n) m=m*2;
    return m;
}

ll c(int n,int r){
    if(r==n || r==0) return 1;
    else if(r==1) return n;
    else return c(n-1,r-1)+c(n-1,r);
}

int main(){
   int n,p,r0=0,r1=0;
   cin >> n >>p;
   vector<int> a(n);
   rep(i,n){
       cin >> a[i];
       a[i]%=2;
       if(a[i]==0) r0++;
       else r1++;
   }
   ll ans=0;
   if(p==1){
       for(int i=0;2*i+1<=r1;i++) ans+=c(r1,2*i+1);
       ans*=f(r0); 
   }else{
       for(int i=0;2*i<=r1;i++) ans+=c(r1,2*i);
       ans*=f(r0);
   }
   cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    cout << (n == m ? "Yes" : "No") << EOL;
}


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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    string ans = s;
    for (int i = 0; i < s.size(); i++)
        if (ans.at(i) + n > 'Z')
            ans.at(i) = (ans.at(i) + n - ('Z' - 'A' +1));
        else
            ans.at(i) = (ans.at(i)  + n);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, in;
	vi v;
	cin >> n;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
	}
	rep(i, n) {
		int j;
		for (j = 0; v[i]%2==0; j++) {
			v[i] /= 2;
		}
		v[i] = j;
	}
	cout << *min_element(all(v)) << endl;;
}

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

int main() {
  int a, b, c; cin >> a >> b >> c;
  for(int i = 1; i <= b; i++) {
    if ((a*i)%b == c) {
      p("YES");
      return 0;
    }
  }
  p("NO");
}

Measured memory_bytes: 256
n = int(input())
a,b,c=[0]*n,[0]*n,[0]*n

for i in range(n):
  a[i],b[i],c[i]=map(int,input().split())

dp=[[0]*3 for _ in range(n)]
dp[0]=[a[0],b[0],c[0]]

for i in range(0,n-1):
  dp[i+1][0]=max(dp[i+1][0],dp[i][1]+a[i+1],dp[i][2]+a[i+1])
  dp[i+1][1]=max(dp[i+1][1],dp[i][2]+b[i+1],dp[i][0]+b[i+1])
  dp[i+1][2]=max(dp[i+1][2],dp[i][0]+c[i+1],dp[i][1]+c[i+1])

print(max(dp[n-1]))

Measured memory_bytes: 62168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  bool flag;
 
  cin >> s;
 
  sort(s.begin(),s.end());
 
  flag = (s[0]==s[1])&(s[1]!=s[2])&(s[2]==s[3]);
 
  cout << (flag?"Yes":"No") << endl;}

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

int main(){
    int n,q;cin>>n>>q;
    string s;cin>>s;
    vector<int> l(q),r(q);
    for(int i=0;i<q;i++){
        cin>>l[i]>>r[i];
    }

    int ac[n+1]={0};

    for(int i=0;i<n;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            ac[i+1] = ac[i] + 1;
        }
        else ac[i+1] = ac[i];
    }

    int ans = 0;
    
    for(int i=0;i<q;i++){
        ans = ac[r[i]] - ac[l[i]-1];

        if(s[r[i]-1]=='A' && s[r[i]]=='C') ans--;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 2176
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int goal[] = new int[3];
        ArrayList<Integer> take = new ArrayList<>();
        for (int i=0; i<3; i++) {
            goal[i] = in.nextInt();
        }
        for (int i=0; i<N; i++) {
            take.add(in.nextInt());
        }
        out.println(newtake(take, goal));
    }

public int minmp2(ArrayList<Integer> take, int[] goal) {
        int mp = 1_000_000_000;
        ArrayList<Integer> takec = new ArrayList<>(take);
        for (int i=0; i<takec.size(); i++) {
            for (int j=0; j<takec.size(); j++) {
                if(i == j){
                    continue;
                }
                for (int k=0; k<takec.size(); k++) {
                    if(i == k || j == k){
                        continue;
                    }
                    mp = Math.min(mp, Math.abs(goal[0] - takec.get(i)) + Math.abs(goal[1] - takec.get(j)) +Math.abs(goal[2] - takec.get(k)));
                }
            }
        }
        return mp;
    }

public int newtake(ArrayList<Integer> take, int[] goal) {
        int min = 1_000_000_000;
        if(take.size() == 3){
            return minmp2(take, goal);
        }
        for (int i=0; i<=take.size()-2; i++) {
            for (int j=i+1; j<=take.size()-1; j++) {
                ArrayList<Integer> takec = new ArrayList<>(take);
                takec.add(takec.get(i) + takec.get(j));
                takec.remove(i);
                takec.remove(j-1);
                min = Math.min(min, newtake(takec, goal));
            }
        }
        min = Math.min(min+10, minmp2(take, goal));
        return min;

    }

}
}



Measured memory_bytes: 63148
N = int(input())
W = [input() for i in range(N)]
a = set()
b = W[0][0] 
OK = True
for w in W:
    if b[-1]!=w[0] or w in a:
        OK = False
    a.add(w)
    b = w
print('Yes' if OK else 'No')


Measured memory_bytes: 38384
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int tmp, x, y;
    for(;;){
        scanf("%d %d", &x, &y);
        if(x >= y){
            tmp = x;
            x = y;
            y = tmp;
        }
        if(x == 0 && y == 0) break;
        printf("%d %d\n", x, y);
    }
    return 0;
}

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


int main(){
	int n,a[200],count[200];

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

	for(int i=0;i<200;i++)count[i]=0;
	for(int i=0;i<n;i++){
		if(a[i]%2==0){
			count[i]++;
			a[i]=a[i]/2;
			i=i-1;
		}
	}
	sort(count,count+n);
	cout<<count[0]<<endl;
}

Measured memory_bytes: 256
def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int,ss_raw()))


poss = []
for i in range(5):
    p = int_raw()
    poss.append(p)
k = int_raw()

def main():
    for i in range(5):
        for j in range(i):
            if abs(poss[i]-poss[j])>k:
                return ":("
    return "Yay!"

print(main())

Measured memory_bytes: 3064
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(1,n-1):
    mini=min(p[i-1],p[i],p[i+1])
    maxi=max(p[i-1],p[i],p[i+1])
    if p[i]!=mini and p[i]!=maxi:
        ans+=1
print(ans)
    


Measured memory_bytes: 3060
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
C = 0
for i in range(q):
    l = 0
    r = n
    while r - l > 1:
        m = (r + l) // 2
        if T[i] <= S[m]:
            r = m
        else:
            l = m
    if (T[i] == S[l]) or (T[i] == S[r]):
        C += 1
print(C)


Measured memory_bytes: 16704
#include <bits/stdc++.h>
#define MS(x,y) memset(x,y,sizeof x);
#define FOR(i,x,y) for(int i = x; i <= y; ++i)
#define rFOR(i,x,y) for(int i = x; i >= y; --i)
#define pb push_back
#define ll long long
using namespace std;

int n;
int a[400][400];
bool vis[400][400];


int main()
{
    scanf("%d",&n);
    FOR(i,0,n - 1) FOR(j,0,n - 1) scanf("%d",&a[i][j]);
    ll ans = 0;
    FOR(i,0,n - 1) FOR(j,i,n - 1) ans += a[i][j];

    bool flag = true;
    FOR(k,0,n - 1)
    FOR(i,0,n - 1) FOR(j,0,n - 1)
        if(a[i][k] + a[k][j] < a[i][j])
        {
            flag = false;
            break;
        }else if(a[i][k] + a[k][j] == a[i][j] && !vis[i][j] && k != i && k != j)
        {
            vis[i][j] = true;
            vis[j][i] = true;
            ans -= a[i][j];
        }
    if(!flag) printf("-1\n");
    else printf("%lld\n",ans);

    /*FOR(i,0,n - 1)
    {
        FOR(j,i + 1,n - 1)
        {
            FOR(k,0,n - 1) if(k != i && k != j)
            {
                if(a[i][k] + a[j][k] == a[i][j])
                    ans -= a[i][j];
            }
        }
    }
    printf("%lld\n",ans);*/

    return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=1010;
int n,a[maxn],ans=1;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
			if(a[i]%3&&a[i]%5)
				ans=0;
	}
	if(ans)
		printf("APPROVED");
	else
		printf("DENIED");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#define repi(i,x,n) for(int i = x; i < n; i++)
#define rep(i,n) repi(i,0,n)
using namespace std;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 1010;
int N;
vector<int> cnt;
vector<pair<int, int>> T[MAX_N];
vector<int> used(MAX_N, 0);
int dfs(int depth)
{
    used[depth] = 1;
    int res = 0;
    for(int u = 0; u < (int)T[depth].size(); u++)
    {
        pair<int, int> e = T[depth][u];
        if(used[e.first]) continue;
        if(cnt[e.first] > 0) res += e.second;
        else res += min(e.second,dfs(e.first));
    }
    return res;
}
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    cnt.resize(N, 0);
    for(int i = 1; i < N; i++) cin >> cnt[i];
    for(int i = 0; i < N - 1; i++)
    {
        int u, v, p; cin >> u >> v >> p;
        T[u].push_back(make_pair(v, p));
        T[v].push_back(make_pair(u, p));
    }
    cout << dfs(0) << endl;
    return 0;
}



Measured memory_bytes: 3264
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

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

	long int ans = k*pow(k-1, n-1);
	cout << ans << endl;

	return 0;
}

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

int main(){
  int N,A,B,p1;
  cin>>N>>A>>B;
  p1=A*N;
  cout<<(p1>=B ? B:p1)<<endl;
}

Measured memory_bytes: 256
N, T = [int(n) for n in input().split()]
CT = [[int(n) for n in input().split()] for _ in range(N)]

def main():
    li = list(filter(lambda t: t[-1] <= T, CT))
    if li:
        li.sort(key=lambda t: t[0])
        print(li[0][0])
    else:
        print('TLE')

if __name__ == '__main__':
    main()

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

using namespace std;

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

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

    int q;
    cin >> q;
    while (q--) {
        int k;
        cin >> k;
        cout << lower_bound(a.begin(), a.end(), k) - a.begin() << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;


ll a[100005];
ll b[100005];
const ll mod = 998244353;

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

    REP(i,n){
        cin >> a[i];
        b[a[i]]++;
    }

    if(a[0] != 0 or b[0] != 1) cout << 0 << endl;
    else
    {
        ll ans = 1;
        REP(i,n)
        {
            if (i == 0) continue;
            ans *= b[a[i]-1];
            ans %= 998244353;
        }
            
        cout << ans << endl;;   
    }
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, a, x, ans = 0;
  scanf("%lld%lld", &n, &a);
  ll dp[n + 1][a * n + 1];
  for(i = 0; i <= n; ++i) for(j = 0; j <= a * n; ++j) dp[i][j] = 0;
  dp[0][0] = 1;
  for(i = 0; i < n; ++i) {
    scanf("%lld", &x);
    for(j = n - 1 ; j >= 0; --j) for(k = 0; k < a * n; ++k) if(k + x <= a * n) dp[j + 1][k + x] += dp[j][k];
  }
  for(i = 1; i <= n; ++i) ans += dp[i][i * a];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 1152
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

#$stdin = File.open('input.txt')
n,m = gsmi
to = Array.new(n){ n }
m.times do
  a,b = gsmi
  to[a-1] = min(to[a-1],b-1)
end

ans,now = 0,0
while now<n
  now = to[now..-1].min
  ans += 1
end

puts ans-1


Measured memory_bytes: 15124
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int p[25];
	float t[25];
	bool x[25]={0};
	for(int i=1;i<25;i++){
		cin>>p[i]>>t[i];
	}
	for(int i=0;i<=16;i=i+8){
		float max=100.0,max2=100.0;
		int cnt=0,cnt2=0;
		for(int j=1;j<=8;j++){
			if(max2>t[j+i]){
				if(max>t[i+j]){
					max2=max;
					max=t[i+j];
					cnt2=cnt;
					cnt=i+j;
				}else{
					max2=t[i+j];
					cnt2=i+j;
				}
			}
		}
		x[cnt]=1,x[cnt2]=1;
		printf("%d %.2lf\n%d %.2lf\n",p[cnt],max,p[cnt2],max2);
	}
	float y=100.0,z=100.0;
	int cnt3=0,cnt4=0;
	for(int i=1;i<=24;i++){
		if(x[i]==0){
			if(z>t[i]){
				if(y>t[i]){
					z=y;
					y=t[i];
					cnt4=cnt3;
					cnt3=i;
				}else{
					z=t[i];
					cnt4=i;
				}
			}
		}
	}
	printf("%d %.2lf\n%d %.2lf\n",p[cnt3],y,p[cnt4],z);
	return 0;
}

Measured memory_bytes: 3152
import Foundation

extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
}

func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}


/************** main *****************/

let rdx = readIntSplit(by: " ")
var (r, d, x) = (rdx[0], rdx[1], rdx[2])
for i in 0 ..< 10 {
    x = r * x - d
    print(x)
}


Measured memory_bytes: 7908
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
from collections import Counter,deque,defaultdict
# import itertools
import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
a,b,x=n1()

m=b*a**2
if m>=2*x:
    ans=math.atan(a*b**2/(2*x))
else:
    ans=math.atan(2*b/a-2*x/(a**3))
print(ans*180/math.pi)

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

struct dat{ int s,t,e; };

int main() {
	int n,m;  cin >> n >> m;
	vector<dat> ste;
	int s,t,e;
	while(cin >> s >> t >> e,s) ste.push_back({s-1,t-1,e});
	int l; cin >> l;
	while(l--) {
		vector<int> b(m),sal(n);
		for(auto&a:b) cin >> a;
		for(int i=0;i<ste.size();++i)
			sal[ste[i].s]+=b[ste[i].t]*ste[i].e;
		for(int i=0;i<n;++i) {
			if(i) cout << " ";
			cout << sal[i];
		}
		cout << endl;
	}
	
	return 0;
}



Measured memory_bytes: 3856
#include<bits/stdc++.h>
using namespace std;
long long read(){
    long long ret=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-f;ch=getchar();}
    while(ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
    return ret*f;
}
int ans;
bool v[1000];
int main(){
	int m,d;
	m=read();
	d=read();
	for(int i=1;i<=m;i++){
		for(int j=2;j<10;j++){
		    int x=i/j;
			if(i%j==0&&x<10&&x>=2){
				if(x==j&&10*x+j<=d&&v[10*x+j]==false){
					ans++;
					//v[10*i+j]==true;
					//cout<<i<<" "<<(10*x+j)<<endl;
					continue;
				}
				if(10*x+j<=d){
					ans++;
					//v[10*i+j]==true;
					//cout<<i<<" "<<(10*x+j)<<endl;
				}
				
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")

int main()
{

    int n;
    cin >> n;
    int arr[n];
    for(int i = 0;i < n;i++)
    {
        cin >> arr[i];
    }
    int sol = 0;
    set<int> st;
    st.insert(INT_MAX);
    for(int i= 0;i < n;i++)
    {
        if(*st.begin() > arr[i])
        {
            sol++;
        }
        st.insert(arr[i]);
    }
    cout << sol;
    return 0;
}


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

#define loop(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define dump(a) cerr << #a << " = " << (a) << "(L:" << __LINE__ << ")" << endl

void solve(long long N) {
    vector<int> ps;
    loop (k, 2, 1000001) {
        auto cnt = 0;
        while (N % k == 0) {
            N /= k;
            cnt++;
        }
        if (cnt) {
            ps.push_back(cnt);
        }
    }
    if (N != 1) {
        ps.push_back(1);
    }

    int ans = 0;
    rep (i, ps.size()) {
        int a = ps[i];
        loop (t, 1, ps[i]+1) {
            if (t <= a) {
                a -= t;
                ans++;
            } else {
                break;
            }
        }
    }
    cout << ans << endl;

}

int main() {
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3688
L, R = map(int, input().split())
li = []

if R-L >= 2018:
  ans = 0
else:
  for i in range(L, R+1):
    l = i % 2019
    li.append(l)
  ans = 10000
  for i in range(len(li)-1):
    for j in range(i+1, len(li)):
      ans = min((li[i]*li[j])%2019, ans)
  
print(ans)

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

int main(){
	int s,t;
	scanf("%d%d", &s, &t);
	int p,q,M;
	scanf("%d%d%d", &p, &q, &M);
	int y;
	scanf("%d", &y);
	printf("%d\n", t^s^y);
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int a, b, w;
    cin >> w >> a >> b;
    if(a+w<b){
        cout << b-a-w;
    }else if(b+w<a){
        cout << a-b-w;
    }else{
        cout << 0;
    }
    return 0;
}

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

int main() {
  int N;
    cin >> N;
  
  int A, B, C;
  A = N%1110;
  B = N/1000;
  C = N - 1000*B;
  
  if( (A < 10) || (C%111 == 0)){
      cout << "Yes" <<endl;
    }
  
  else{
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
	int k;
	double x[3], y[3], a, b, c, d, e, f, l , m, n;
	cin >> k;
	while(k--){
		cin>> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
		a = 2 * (x[1] - x[0]);
		b = 2 * (y[1] - y[0]);
		c = ( (x[1]*x[1]) + (y[1]*y[1]) ) -( (x[0]*x[0]) + (y[0]*y[0]) );
		d = 2 * (x[2] - x[0]);
		e = 2 * (y[2] - y[0]);
		f = ( (x[2]*x[2]) + (y[2]*y[2]) ) -( (x[0]*x[0]) + (y[0]*y[0]) );
		l = (c*e - f*b) / (a*e - d*b);
		m = (c*d - f*a) / (b*d - e*a);
		n = sqrt((l - x[0])*(l - x[0]) + (m - y[0])*(m - y[0]));
		cout << fixed << setprecision(3) << l << " " << m << " " << n << endl;
	}
}

Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
//ll mod = 998244353;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = n;
	int c = 1;
	for (int i = 0; i < n; i++) {
		if (a[i] == c) {
			c++; ans--;
		}
	}
	if (ans == n) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<pll> p(N);
  for (ll i = 0; i < N; ++i) {
    ll x, y;
    cin >> x >> y;
    p.at(i) = {x, y};
  }
  ll pp = -INF, pm = -INF, mp = -INF, mm = -INF;
  for (ll i = 0; i < N; ++i) {
    pp = max(pp, p.at(i).first + p.at(i).second);
    pm = max(pm, p.at(i).first - p.at(i).second);
    mp = max(mp, -p.at(i).first + p.at(i).second);
    mm = max(mm, -p.at(i).first - p.at(i).second);
  }
  cout << max(pp + mm, mp + pm) << "\n";
}


Measured memory_bytes: 6352
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,i,cnt=0,j;
	scanf("%lld",&n);
	long long int a[n];
	map<long long int,long long int> mp;
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
		mp[a[i]]++;
	}
	sort(a,a+n);
	long long int maxi=a[n-1];
	bool check[maxi+1]={false};
	if(mp[1]>1)
	cout<<"0\n";
	else if(mp[1]==1)
	cout<<"1\n";
	else
	{
	for(i=0;i<n;i++){
		if(mp[a[i]]>1){
			if(!check[a[i]]){
			for(j=a[i]+a[i];j<=maxi;j+=a[i]){
					if(!check[j])
					check[j]=true;
			}
		}
			continue;
		}
		else{
			if(check[a[i]]){
				for(j=a[i]+a[i];j<=maxi;j+=a[i]){
					if(!check[j])
					check[j]=true;
				}
			}
			else{
				cnt+=1;
				for(j=a[i]+a[i];j<=maxi;j+=a[i]){
					if(!check[j])
					check[j]=true;
				}
			}
		}
	}
	printf("%lld",cnt);
}
	return 0;
}

Measured memory_bytes: 18680
// This template code suggested by KT BYTE Computer Science Academy
//   for use in reading and writing files for USACO problems.

// https://content.ktbyte.com/problem.java

import java.util.*;
import java.io.*;

public class Main {

    static StreamTokenizer in;

    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static void main(String[] args) throws Exception {
        in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = nextInt();
        int[] vals = new int[n];
        long[] prefixSum = new long[n + 1];

        for (int i = 0; i < n; i++) {
            vals[i] = nextInt();
            prefixSum[i + 1] = vals[i] + prefixSum[i];
        }

        Long[][] dp = new Long[n][n];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dp[i][j] = 10000000000000L;
            }
        }

        for (int L = n-1; L >= 0; L--) {
            for (int R = L; R < n; R++) {
                if (L == R) dp[L][R] = 0L;
                else {
                    long j = prefixSum[R + 1] - prefixSum[L];

                    for (int i = L; i < R; i++) {
                        dp[L][R] = Math.min(dp[L][R], dp[L][i] + dp[i + 1][R] + j);
                    }
                }
            }
        }

        out.println(dp[0][n-1]);
        out.close();
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  vector<int> t(N);
  string X;
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  cin >> X;
  
  int ans = 0;
  bool flag = false;
  for (int i = 0; i < N; i++) {
    if (flag) ans += t[i];
    if (s[i] == X) flag = true;
  }
  
  cout << ans << endl;
  
  return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI acos(-1)
#define EPS 1e-12
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bitCount __builtin_popcount
#define forn(i, n) for(i = 0; i < (ll)n; i++)
#define for1(i, n) for(i = 1; i <= (ll)n; i++)
#define forv(i, v) for(i = 0; i < v.size(); i++)
#define forab(i, a, b) for(i = a; i <= (ll)b; i++)
#define Sort(v) sort(v.begin(), v.end())
#define bend(v) v.begin(), v.end()
#define sz(v) v.size()
#define trace(x) cout<<"x = "<<x<<"\n"
#define trace2(x, y) cout<<"x = "<<x<<" y = "<<y<<"\n"
#define trace3(x, y, z) cout<<"x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define trace4(w, x, y, z) cout<<"w = "<<w<<" x = "<<x<<" y = "<<y<<" z = "<<z<<"\n"
#define ln "\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef set<int>::iterator sit;
typedef set<ll>::iterator sllt;
typedef set<char>::iterator sct;
typedef map<int, int>::iterator mit;
typedef vector<int>::iterator vit;
typedef multiset<int>::iterator msit;
const int maxn = 2e5+5;
const ll mod = 1e9+7;
const int alphabet = 26;
const int inf = INT_MAX;
const ll linf = 1e18+9;
namespace util{
	inline ll cnm(char ch){ return (ch-'0'); }
	inline ll cap(char ch){ return (ch-'a'); }
	inline void instr(string& s, ll& n){ cin>>s;    n = s.length(); }
	inline void instr(string& s){ cin>>s; }
	template<typename T> T gcd(T a, T b){ if(a==0) return b; return gcd(b%a, a); }
	template<typename T> bool min(T a, T b, T c){
		return  std::min(a, std::min(b, c));
	}
}
using namespace util;

ll a[maxn];
void solve(int tc)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	ll i, j, k, m, n;
	cin>>n;
	for(i = 0; i < n; i++) cin>>a[i];
	ll tsar = a[0];
	for(i = 1; i < n; i++){
		tsar ^= a[i];
	}

	for(i = 0; i < n; i++){
		cout<<(tsar^a[i])<<" ";
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	int i = 1;
	// cin>>t;
	while(i <= t){
		solve(i);
		i++;
	}

	return 0;
}



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

int main(void){
  int N, K;
  cin >> N >> K;
  int A[N];
  for(int i=0; i<N; i++) {
    cin >> A[i];
  }
  bool dp[K+1];
  // true: 先行が勝つ, false: 後攻が勝つ
  for(int i=0; i<K+1; i++) dp[i] = false;
  
  for(int i=0; i<K+1; i++){
    for(int j=0; j<N; j++){
      bool contFlag = false;
      if(i-A[j] >= 0){
        if(!dp[i-A[j]]) dp[i] = true;
        contFlag = true;
      }
      if(!contFlag) break;
    }
  }
  /*
  for(int i=0; i<K+1; i++){
    cout << i << ", " << dp[i] << endl;
  }
  */
  
  if(dp[K]) cout << "First" << endl;
  else cout << "Second" << endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


ll dp[3010][3010];
ll a[3010];

ll solve(int head, int tail) {
    if(dp[head][tail] != -1) return dp[head][tail];
    if(head == tail) return a[head];

    ll ret = max(a[head]-solve(head+1, tail), a[tail]-solve(head, tail-1));

    dp[head][tail] = ret;

    return dp[head][tail];
}


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

    rep(i, 3009) rep(j, 3009) {
        dp[i][j] = -1;
    }

    cout << solve(0, n-1) << endl;

    return 0;
}


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

int main(){
  string str;
  cin >> str;
  int a=0, b=0, c=0;
  for(int i=0; i<str.length(); i++){
    if(str[i] == 'a') a++;
    else if(str[i] == 'b') b++;
    else c++;
  }
  if(abs(a-b)<=1 && abs(b-c)<=1 && abs(c-a)<=1) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3720
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val a = readLine()?.split(" ")?.map(String::toInt) ?: return
    val order = hashMapOf<Int, Int>()

    a.forEachIndexed { i, c ->
        order[c] = i + 1
    }

    val o = 1.until(n + 1).joinToString(separator = " ") { order[it].toString() }
    println(o)
}

Measured memory_bytes: 60696
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define ll long long
#define Mid ((L+R)/2)
#define pi pair<int,int>
#define pii pair<int,pi>
#define deb(x) cout<<#x<<"="<<x<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int N = 2e5 + 7;
int dp[5*N],lazy[5*N],n,k,a[20],b[20];
int mod=998244353;
int sum(int x,int y)
{
    x+=y;
    if(x>=mod)x-=mod;
    return x;
}
void Lazy(int p,int L,int R)
{
    dp[p]=sum(dp[p],lazy[p]);
    if(L!=R)
    {
        lazy[2*p]=sum(lazy[p],lazy[2*p]);
        lazy[2*p+1]=sum(lazy[p],lazy[2*p+1]);
    }
    lazy[p]=0;
    return;
}
int get(int i,int p=1,int L=1,int R=n)
{
    Lazy(p,L,R);
    if(L==R)
        return dp[p];
    if(i<=Mid)
        return get(i,2*p,L,Mid);
    return get(i,2*p+1,Mid+1,R);
}
void upd(int l,int r,int x,int p=1,int L=1,int R=n)
{
    Lazy(p,L,R);
    if(l>R || r<L)
        return;
    if(L>=l&&R<=r)
    {
        lazy[p]=x;
        Lazy(p,L,R);
        return;
    }
    upd(l,r,x,2*p,L,Mid);
    upd(l,r,x,2*p+1,Mid+1,R);
    return;
}
int main()
{
    scanf("%d %d",&n,&k);
    for(int i=0;i<k;i++)
        scanf("%d %d",a+i,b+i);
    upd(1,1,1);
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<k;j++)
        {
            int L=i+a[j];
            int R=i+b[j];
            if(L>n)
                continue;
            R=min(R,n);
            upd(L,R,get(i));
        }
    }
    printf("%d",get(n));
    return 0;
}


Measured memory_bytes: 7852
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    string A;
    cin >> A;
    vector<ll> num_char(26);
    for (auto &c : A) {
        num_char[c - 'a']++;
    }
    ll res = 1;
    REP(i, 25) {
        FOR(j, i + 1, 26) {
            res += num_char[i] * num_char[j];
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll mod=1000000007;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N,time=0;
	cin>>N;
	vector<pair<int,int>> tab(N);
	for(int i=0;i<N;i++) cin>>tab[i].first>>tab[i].second;
	sort(tab.begin(),tab.end(),[](auto &left,auto &right){
		return left.second < right.second;
	});
	for(int i=0;i<N;i++){
		time+=tab[i].first;
		if(time>tab[i].second){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>

int main()

{
      char str[1001];
      scanf("%s",str);
      int n, i;
      scanf("%d",&n);
      for(i=0; i<strlen(str);i=i+n)
             {
                   printf("%c",str[i]);
             }
printf("\n");
return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

struct edge {int to;double cost;};

int n,m;
int V;
vector<vector<edge>> G;
double d[30][1<<8];
vi t;
const double INF=1e8;

void solve(int s){
    priority_queue<pair<double,pi>> q;
    rep(i,m)rep(j,1<<n)d[i][j]=INF;
    d[s][0]=0;
    q.push({0,{s,0}});
    while(!q.empty()){
        auto top=q.top();
        q.pop();
        double c=-top.fi;
        int v=top.se.fi;
        int u=top.se.se;
        if(d[v][u]<c)continue;
        for(auto e:G[v]){
            rep(j,n){
                // if j-th ticket is not used
                if(((u>>j)&1)==0) {
                    double cost = e.cost/t[j];
                    int nu=u|1<<j;
                    if(d[e.to][nu]>d[v][u]+cost){
                        d[e.to][nu]=d[v][u]+cost;
                        q.push({-d[e.to][nu],{e.to,nu}});
                    }
                }
            }
        }
    }
}
    
void run(){
    int p,a,b;
    cin>>n>>m>>p>>a>>b;
    if(!n)return;
    a--,b--;
    t=vi(n);
    G=vector<vector<edge>>(m);
    rep(i,n)cin>>t[i];
    rep(i,p){
        int x,y;
        double z;
        cin>>x>>y>>z;
        x--,y--;
        G[x].pb({y,z});
        G[y].pb({x,z});
    }
    solve(a);
    double ans=INF;
    rep(i,1<<n){
        ans=min(ans,d[b][i]);
    }
    if(ans==INF)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
    run();
}


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

int main(){
  int n;
  cin >> n;
  int b[110];
  b[0] = 1000000;
  for (int i=1; i<n; i++){
    cin >> b[i];
  }
  b[n] = 1000000;
  
  int s = 0;
  for (int i=0; i<n; i++){
    s += min(b[i],b[i+1]);
  }
  printf("%d", s);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    bool[] visit;
    void Run()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();
        Console.WriteLine(n - k + 1);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 11092
import sys
#fin = open("test.txt", "r")
fin = sys.stdin

n = int(fin.readline())
A = list(map(int, fin.readline().split()))
q = int(fin.readline())
m_list = list(map(int, fin.readline().split()))

for m in m_list:
	can_compose = False
	s = [[] for i in range(n)] #s[i][m]??§???A[i]?????§???????´???§m????????????????????????????????????
	for i in range(n):
		s[i] = [False for i in range(m + 1)]

	for j in range(m + 1):
		if j == A[0]:
			s[0][j] = True
		else:
			s[0][j] = False
		
	if s[0][m]:
		can_compose = True
		
	if not can_compose:
		for i in range(1, n):
			for j in range(m + 1):
				if j == A[i]:
					s[i][j] = True
				elif s[i - 1][j]:
					s[i][j] = True
				else:
					if j - A[i] >= 0:
						s[i][j] = s[i - 1][j - A[i]]
			
			if s[i][m]:
				can_compose = True
				break

	if can_compose:
		print("yes")
	else:
		print("no")

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

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  
  int ans=0;
  for (int i=0;i<=n;++i){
    int sum=0;//sum=桁の和
    int x=i;//一時的な変数
    for (int j=0;j<5;++j){
      sum+=x%10;//一の位の数字をsumに加算
      x/=10;
    }
    if (a<=sum&&sum<=b){
      ans+=i;
    }
  }
    cout << ans << endl;
}
  
    


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main(){
	string W, Ti;
	cin >> W;
	for (int i = 0; i < W.size(); i++){
		W[i] = tolower(W[i]);
	}

	int n = 0;

	while (1){
		cin >> Ti;
		if (Ti == "END_OF_TEXT") break;
		
		for (int j = 0; j < Ti.size(); j++){
			Ti[j] = tolower(Ti[j]);
		}
		if (Ti == W) n++;
	}

	cout << n << "\n";

	return 0;
}


Measured memory_bytes: 3168