akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin >> s;
	bool f;
	for(int i = 0;i < s.size();i++)
	{
		f = 0;
		if(i % 2 == 1)
		{
			if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
				f = 1;
		}
		else
		{
			if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
				f = 1;
		}
		if(f == 0)
			break;
	}
	if(f)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
	return 0;
}

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

using  namespace  std;

#define PI              acos(-1.0)
#define lcm(a,b)        (a * (b / __gcd(a,b)))
#define en '\n'

#define READ_IN freopen("Input.txt","r",stdin);
#define READ_OUT freopen("Output.txt","w",stdout);


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

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define trace(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define trace(x...)
#endif

typedef long long int           ll;
typedef unsigned long long int  llu;

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

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

    int st =1;
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==st)
        {
            cnt++;
            st++;
        }

    }

    if(cnt!=0)
    cout << n-cnt << endl;
    else
        cout << -1 << endl;


    return 0;
}


Measured memory_bytes: 1024
import math

X, Y = input().split(" ")
X, Y = int(X), int(Y)

comb_list = {}
mod_param = 10**9 + 7

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

# ax ≡ 1 (mod m)
def modinv(a, m):
    (inv, q, gcd_val) = egcd(a, m)
    return inv % m

def comb(a, b):
  ans = 1
  for i in range(b+1, a+1):
    ans *= i
    ans %= mod_param
  for i in range(1, a-b+1):
    k = modinv(i, mod_param)
    ans *= k
    ans %= mod_param
  return ans

if (abs(2*X-Y)%3 != 0):
  print(0)
else:
  alpha = (2*Y-X)//3
  beta = (2*X-Y)//3
  if alpha > beta:
    print(comb(alpha+beta, beta))
  else:
    print(comb(alpha+beta, alpha))


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <map>

using namespace std;

int main()
{
  long long n, k, ans;
  cin>>n>>k;
  n=n%k;
  ans=n;
  while(true){
     if(n>=abs(n-k)){
        ans=abs(n-k);
        n=abs(n-k);
     }else{break;}
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n , cnt = 0 ;
	cin >> n ;
  int arr[n + 1] , h[n + 1] ;
  for(int i = 1 ;i  <= n ; i++){
    cin >> arr[i] ;
    if(arr[i] != i) cnt++ ;
  }
  if(cnt > 2)cout << "NO" ;
  else cout << "YES" ;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b,c;
	cin >> a >> b >>c;
	if ((a-b) < c) {
		cout << c-(a-b) << endl;
	} else {
		cout << 0 << endl;
	}
	return 0;
}


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

int main() {
  ll N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  N -= 1;
  ll dif = abs(A - B);
  vector<vector<ll>> pos;
  bool ok = false;
  for (ll i = 0; i <= N; ++i) {
    // cout << -D * i + C * (N - i) << ' ' << D * (N - i) - C * i << "\n";
    if ((-D * i + C * (N - i) <= dif) && (dif <= D * (N - i) - C * i)) {
      ok = true;
    }
  }
  if (ok) {
    cout << "YES" << "\n";
  }
  else {
    cout << "NO" << "\n";
  }
}


Measured memory_bytes: 3636
def main():
    a,b = map(int, input().split())
    s = input()

    if s[a] != '-':
        print('No')
        exit()
    
    slist = list(s)
    slist[a] = ''

    if ''.join(slist).isdigit():
        print('Yes')
        exit()

    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    vector<vector<int>> a(3,vector<int>(3));
    rep(i,3){
        rep(j,3)cin >> a[i][j];
    }
    int n;
    cin >> n;
    vector<int>b(n);
    rep(i,n)cin >> b[i];
    
    rep(i,n){
        rep(j,3){
            rep(k,3){
                if(b[i] == a[j][k]) a[j][k] = -1;
            }
        }
    }
    bool bingo = false;
    rep(i,3){
        if(a[i][0]+a[i][1]+a[i][2] == -3)bingo = true;
        if(a[0][i]+a[1][i]+a[2][i] == -3)bingo = true;
    }
    if(a[0][0]+a[1][1]+a[2][2] == -3)bingo = true;
    if(a[0][2]+a[1][1]+a[2][0] == -3)bingo = true;
    
    if(bingo)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
 int n;
 cin>>n;
 int d[n];
 for(int i=0;i<n;i++)cin>>d[i];
 if(d[0]!=0){
   cout<<0;
   return 0;
 }
 int ans=1;
 sort(d,d+n);
 int k1=1,k2=0,t=0,count=0;
 for(int i=1;i<n;i++){
   while(d[i]!=count){
     count++;
     k2=k1;
     k1=0;
   }
   k1++;
   ans=(ans*k2)%998244353;
 
 }
 cout<<ans;



return 0;
}


Measured memory_bytes: 1024
import java.util.*;

class Main {
    static ArrayList<Long>[] g;
    static long[] d;
    static void dfs(int v,long u,int p){
        d[v]=u;
        for(long we:g[v]){
            int w=(int)(we>>>32);
            long e=(int)we;
            if(w==p)continue;
            dfs(w,u+e,v);
        }
    }
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=scan.nextInt();
        g=new ArrayList[n];
        for(int i=0;i<n;++i)g[i]=new ArrayList<Long>();
        for(int i=0;i<n-1;++i){
            int a=scan.nextInt()-1;
            int b=scan.nextInt()-1;
            long c=scan.nextInt();
            g[a].add((long) b << 32 | c);
            g[b].add((long) a << 32 | c);
        }
        int q=scan.nextInt(),k=scan.nextInt()-1;
        d=new long[n];
        dfs(k,0,-1);
        while(q-->0){
            int x=scan.nextInt()-1;
            int y=scan.nextInt()-1;
            System.out.println(d[x]+d[y]);
        }
    }
}


Measured memory_bytes: 189332
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<vector>
#include<algorithm>
#include<utility>
#include<queue>


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;
const int MAXN=3000;
const int dir[4][2]={{0,1},{0,-1},{-1,0},{1,0}};

typedef pair<int,int> pii;


int main(){
	#ifdef L_JUDGE
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);
    for(int x=sx;x<tx;x++){
        printf("R");
    }
    for(int y=sy;y<ty;y++){
         printf("U");
    }
    for(int x=tx;x>sx;x--){
        printf("L");
    }
    for(int y=ty;y>sy;y--){
         printf("D");
    }
    printf("D");
    for(int x=sx;x<=tx;x++){
        printf("R");
    }
    for(int y=sy;y<=ty;y++)
        printf("U");
    printf("L");
    printf("U");
    for(int x=sx;x<=tx;x++){
        printf("L");
    }
    for(int y=sy;y<=ty;y++)
        printf("D");
    printf("R");



	#ifdef L_JUDGE
		fclose(stdin);
		fclose(stdout);
//		system("out.txt");
	#endif

	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/tenka1-2019/tasks/tenka1_2019_f
//
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::fmt::*;
use std::io::*;
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MOD: u64 = 998244353;

fn main() {
    input! {
        n: usize, x: usize
    };

    let mut comb = vec![vec![0; 3010]; 3010];
    for i in 0..comb.len() {
        comb[i][0] = 1;
        comb[i][i] = 1;
        for j in 1..i {
            let u = comb[i - 1][j - 1];
            let v = comb[i - 1][j];
            comb[i][j] = (u + v) % MOD;
        }
    }

    let mut ans = 0;
    for sum in 0..x {
        for one in 0..sum + 1 {
            let left = sum - one;
            if left % 2 == 1 {
                continue;
            }
            let two = left / 2;
            if one + two > n {
                continue;
            }
            ans += comb[n][one] * comb[n - one][two] % MOD;
            ans %= MOD;
        }
    }

    for sum in x + 1..2 * n + 1 {
        for one in 1..n + 1 {
            if sum < one {
                continue;
            }
            let two = (sum - one) / 2;
            if one + two * 2 != sum {
                continue;
            }
            if one + two > n {
                continue;
            }
            let prefix = (sum - x) / 2 + 1;
            if (sum - x) % 2 == 0 {
                continue;
            }
            if prefix * 2 > two {
                continue;
            }
            let total = two + one - prefix * 2;
            ans += comb[n][one + two] * comb[total][one] % MOD;
            ans %= MOD;
        }
        if sum % 2 == 0 && x % 2 != 0 {
            ans += comb[n][sum / 2];
            ans %= MOD;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 90364
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
//__int128


int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	//freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int a, b, t;
	cin >> a >> b >> t;
	cout << t / a * b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i = 0; i < M; ++i){
        int a, b;
        cin >> a >> b;
        a--; b--;
        A[a]++, A[b]++;
    }
    for(int i = 0;i < N; ++i){
        cout << A[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	cin >> A >> B >> X;
	bool flag = 0;
	if (X >= A && X <= A + B)flag++;
	if (flag)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
cnt = [0] * 3
for i in range(n):
  if p[i] <= a: cnt[0] += 1
  elif p[i] <= b: cnt[1] += 1
  else: cnt[2] += 1
ans = min(cnt)
print(ans)

Measured memory_bytes: 9000
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
using namespace std;
typedef pair<ll,ll> pll;


ll n, k, a[200005];
ll dp[200005];
ll last[200005];
ll seens[200005];
void does(ll id)
{

        vector< ll > v;
        v.clear();
        for(ll i=id;i<=n;i++) {
                if(seens[a[i]]){
                        while(seens[a[i]]){
                                seens[v.back()]--;
                                v.pop_back();
                        }
                }else {
                        seens[a[i]]++;
                        v.push_back(a[i]);
                }
        }
        if(v.size() > 0){
        for(auto &i : v) cout << i << " "; cout << endl;
        }
}
int main()
{
        cin >> n >> k;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
        }
        dp[n+1] = 0;
        dp[n] = n;
        last[a[n]] = n;
        for(ll i=n-1;i>=1;i--) {
                if(last[a[i]] == 0) dp[i] = i;
                else dp[i] = dp[last[a[i]] + 1];
                last[a[i]] = i;
        }
        vector< ll > v;
        v.pb(a[dp[1]]);

        ll curf = a[dp[1]];
        for(ll i=2;i<=n;i++) {
                if(v.back() == 0) {
                        break;
                }
                ll id = last[curf];
                curf = a[dp[id + 1]];
                //if(curf == 0) break;
                v.pb(curf);
        }
        //v.pb(0);
        //assert(v.size() <= n);
        //for(auto &i : v) cout << i << " "; cout << endl;
        if(v.back() == 0) {
                v.pop_back();
        }
        v.insert(v.begin(), 1, 0LL);
        ll ff = 0;

        ll xx = k-1;
        ll sz = v.size();
        ff = v[(xx)%sz];

        ll id = last[ff];
        does(id+1);

        return 0;
}


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

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

int main() {
  int k;
  cin >> k;
  long long result = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c < b; ++c) {
        result += 2 * gcd(a, gcd(b, c));
      }
      result += gcd(a, b);
    }
  }
  cout << result;
  return 0;
}

Measured memory_bytes: 3148
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

signed main()
{
    fastio
    int n;
    cin>>n;
    int a[n];
    int ans=0;
    int pre[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i!=0)pre[i]=pre[i-1]%MOD+a[i]%MOD;
        else pre[i]=a[i];
    }
    for(int i=n-1;i>=1;i--)
    {
        ans=ans%MOD+((a[i]%MOD)*(pre[i-1])%MOD)%MOD;
        //cout<<pre[i-1]<<" "<<ans<<endl;
    }
    cout<<ans%MOD<<endl;
}


Measured memory_bytes: 6712
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;

class Node {
   public:
   // long vertex;
   vector<long> to;
   // vector<long> length;
   // int grp;
   bool seen = false;
   bool finish = false;
   ll dis[2] = {-1,-1};
   Node(){;};
};
vector<Node*> vGr;

void dfs(int vertex,int dis, int start) {
   auto thisv = vGr[vertex];
   if (thisv->seen) return;
   thisv->seen = true;
   thisv->dis[start] = dis;
   for (auto el : thisv->to) {
      dfs(el,dis+1,start);
   }
   thisv->finish = true;
   return;
};


int main(void) {
   ll N;
   cin>>N;
   ll u,v;
   cin>>u>>v;
   rep(i,0,N) vGr.push_back(new Node());
   rep(i,0,N-1) {
      ll a,b;
      cin>>a>>b;
      vGr[a-1]->to.push_back(b-1);
      vGr[b-1]->to.push_back(a-1);
   }
   dfs(u-1,0,0);
   rep(i,0,N) vGr[i]->seen = false;
   dfs(v-1,0,1);

   ll ans = 0;
   rep(i,0,N) {
      ll a = vGr[i]->dis[1];
      ll b = vGr[i]->dis[0];
      // cout<<i<<" "<<a<<" "<<b<<endl;
      // ll tmp = a-b;
      if (a>=b) chmax(ans,a-1);
      // if (vGr[i]->dis[1]>=vGr[i]->dis[0]) chmax(ans,vGr[i]->dis[1]-vGr[i]->dis[0]-1);
   }
   cout<<ans<<endl;

   return 0;
}

Measured memory_bytes: 14452
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long INF=1e15;
int N;
vector<vector<pair<int,long>>> g(size);
long d[size],pre[size];
priority_queue<pair<long,int>> pq;
void dijkstra(int a){//O(E+NlogN)
	rep(i,0,N){
		d[i]=INF;
		pq.push(make_pair(-d[i],i));
	}
	d[a]=0;pq.push({0,a});
	int v;long temp;
	rep(i,0,N){
		v=pq.top().second;
		pq.pop();
        int u;
		for(int i=0;i<g[v].size();i++){
            u=g[v][i].first;
			temp=d[v]+g[v][i].second;
			if(d[u]>temp){
				d[u]=temp;
				pre[u]=v;
				pq.push({-d[u],u});
			}
		}
	}return;
}
int main(){
	cin>>N;
	int a,b;long c;
	rep(i,0,N-1){
		cin>>a>>b>>c;a--;b--;
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	int Q,K;cin>>Q>>K;
	dijkstra(K-1);
	int x,y;
	rep(i,0,Q){
		cin>>x>>y;
		cout<<d[x-1]+d[y-1]<<endl;
	}
}

Measured memory_bytes: 14320
#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 A[2][100];

void Main()
{
  int N; cin >> N;
  rep(i,2){
    rep(j,N){
      cin >> A[i][j];
    }
  }
  int niretsume = A[0][0];
  rep(j,N) {
    niretsume += A[1][j];
  }
  int maxnum = niretsume;
  for(int j = 1; j < N; j++) {
    niretsume += A[0][j] - A[1][j-1];
    maxnum = max(maxnum, niretsume);
  }
  cout << maxnum << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma optimize("-O3")
#define int long long int
#define f first
#define s second
#define pb push_back
#define endl '\n'
const int N=998244353;

main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	int l[k];
	int r[k];
	for(int i=0; i<k; i++){
		cin>>l[i]>>r[i];
	}
	int dp[n+1];
	int sum[n+1];
	for(int i=0; i<=n; i++){
		sum[i]=0;
		dp[i]=0;
	}
	sum[1]=1;
	dp[1]=1;
	for(int i=2; i<=n; i++){
		for(int j=0; j<k; j++){
			if(i>=l[j]){
				dp[i]=(dp[i]+sum[i-l[j]])%N;
			}
			if(i>=r[j]+1){
				dp[i]=(dp[i]-sum[i-r[j]-1]+N)%N;
			}
		}
		sum[i]=(dp[i]+sum[i-1])%N;
	}
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 6772
/********************************************************************
 * Ejercicio: Knapsack 1                                            *
 * Url: https://atcoder.jp/contests/dp/tasks/dp_d                   *
 * Lenguaje: c++                                                    *
 * Autor: Sebastian Vega                                            *
 * Fecha: 27-08-2020                                                *
 *******************************************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define forn(i, a, b) for (int i = a; i < b; ++i)
#define SZ(x) int(x.size())
#define pb push_back
#define F first
#define S second
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
  cerr << ' ' << H;
  dbg_out(T...);
}

const int N = 101, W = 1e5 + 1;
const ll INF = 1e18;
ll n, k, w[N], v[N], dp[N][W];

ll f(int i, int j) {
  if (j > k) return -INF;
  if (i == n) return 0;
  ll &ans = dp[i][j];
  if (ans != -1) return ans;
  ans = max(f(i + 1, j + w[i]) + v[i], f(i + 1, j));
  return ans;
}

int main() {
#ifdef LOCAL
  freopen("in.txt", "r", stdin);
// freopen("main.txt", "w", stdout);
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
  ios::sync_with_stdio(0);
  cin.tie(0);
#define endl '\n'
#define dbg(...) 18
#endif
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
  memset(dp, -1, sizeof(dp));
  cout << f(0, 0) << endl;
  return 0;
}

Measured memory_bytes: 82508
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <stdio.h>

int main(){
  int n=0;
  std::string s,t;
  std::cin >> s >> t;

  for(int i=0;i<3;i++){
    if(s[i]==t[i]){
      n++;
    }
  }
  
  std::cout << n;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    bool is_res = false;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')is_res = true;
    cout << (is_res?"Yes":"No") << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;   cin >> s;
    int q;      cin >> q;
    int cr = 0;
    string sub;
    rep(i, q){
        int t;  cin >> t;
        if(t == 1)  cr++;
        else{
            int f;  cin >> f;
            string c;   cin >> c;
            if(cr%2){
                if(f == 1){
                    s += c;
                }else{
                    sub += c;
                }
            }else{
                if(f == 1){
                    sub += c;
                }else{
                    s += c;
                }
            }
        }
    }
    reverse(sub.begin(), sub.end());
    s = sub + s;
    if(cr%2)    reverse(s.begin(), s.end());
    cout << s << endl;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

struct N {
  int t;
  ll v;
  ll ji;
};
ll n, t, s, e;

bool operator<(const N &l, const N &r) {
  return l.v - t * l.ji < r.v - t * r.ji;
}

vector<vector<N>> p;
vector<int> visits;
vector<int> par;
vector<bool> used;
bool ok = true;

void dfs(int i, int j, int from) {
  if (used[i]) return;
  used[i] = true;
  par[i] = from;
  for (auto &path : p[i]) {
    if (used[path.t]) continue;
    dfs(path.t, j, i);
  }
}

ll INF = 1LL << 40;

void dfs2(int i, int from) {
  ll du = INF;
  for (auto &path : p[i]) {
    if (path.t == from) {
      du = path.v;
      continue;
    }
    visits[path.t]++;
    if (path.v - t * visits[i] <= 0) {
      ok = false;
      return;
    }
    dfs2(path.t, i);
    visits[i]++;
  }

  if (du - t * (visits[i] + visits[from]) <= 0) {
    ok = false;
  }
  return;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> n >> t >> s >> e;
  s--;
  e--;
  p.resize(n);
  used.resize(n);
  par.resize(n);
  visits.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    ll w;
    cin >> a >> b >> w;
    a--;
    b--;
    p[a].push_back(N{b, w});
    p[b].push_back(N{a, w});
  }
  dfs(s, e, -1);
  for (int i = 0; i < n; i++) {
    for (auto &path : p[i]) {
      path.ji = p[path.t].size() - 1;
    }
  }
  for (int i = 0; i < n; i++) {
    sort(p[i].begin(), p[i].end());
  }

  int now = e;
  vector<int> v;
  while (par[now] >= 0) {
    v.push_back(now);
    now = par[now];
  }
  v.push_back(s);
  reverse(v.begin(), v.end());

  for (int i = 0; i < v.size(); i++) {
    int now = v[i];
    int next = n;
    int prev = -1;
    if (i + 1 < v.size()) next = v[i + 1];
    if (i - 1 >= 0) prev = v[i - 1];

    ll du = INF;
    for (auto &path : p[now]) {
      if (path.t == next) {
        du = path.v;
        continue;
      }
      if (path.t == prev) {
        continue;
      }
      if (path.v - t * visits[now] <= 0) {
        ok = false;
      }
      visits[path.t]++;
      dfs2(path.t, now);
      visits[now]++;
    }
    if (du - visits[now] * t <= 0) {
      ok = false;
    }
    if (next < n) visits[next]++;
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}



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

using namespace std;

typedef long long ll;

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

	int N, Q;
	cin >> N >> Q;

	string S;
	cin >> S;

	vector<int> v(N+1, 0);
	for(int i = 0; i < N-1; i++){
		if(S.substr(i, 2) == "AC"){
			v[i+2] = 1;
		}
	}

	for(int i = 0; i < N; i++){
		v[i+1] += v[i];
	}

	rep(i, Q){
		int l, r;
		cin >> l >> r;
		cout << v[r] - v[l] << endl;
	}

}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

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

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << ":" << #x << " = " << (x) << endl;
#else
#define dbg
#endif

#pragma endregion Macros

int main()
{
    int N,X,T;
    cin >> N >> X >> T;

    int ans = ((N+X-1)/X ) *T;
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main () {
	int counter[101] = {0};
	int max = 0;
	int input , i;
	while(scanf("%d" , &input) > 0) {
		counter[input]++;
		if (counter[input] > max) {
			max = counter[input];
		}
	}
	for(i = 1; i <= 100; i++) {
		if (counter[i] == max) {
			printf("%d\n" , i);
		}
	}
	return 0;
}

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

int main() {
  int n,k,r,s,p;
  string t;
  cin >>n>>k>>r>>s>>p>>t;
  vector<bool> ed(n,false);
  map<char,int> point;
  point['r'] = p;
  point['p'] = s;
  point['s'] = r;
  int ans = 0;
  for(int i = 0; i<n; i++) {
    ans += point[t[i]];
    if (ed[i]) continue;
    for (int j = i; j<n-k; j+=k) {
      ed[j] = true;
      if (t[j] == t[j+k]) {
        ed[j+k] = true;
        ans -= point[t[j]];
        j+=k;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = {
    "M" : 0,
    "A" : 0,
    "R" : 0,
    "C" : 0,
    "H" : 0
  };
  while(hasNext()){
    var first = nextCharArray()[0];
    if(list[first] != null){
      list[first]++;
    }
  }
  var keys = Object.keys(list);
  var output = 0;
  //myerr(keys);
  for(var i = 0; i < keys.length - 2; i++){
    for(var j = i + 1; j < keys.length - 1; j++){
      for(var k = j + 1; k < keys.length; k++){
        output += list[keys[i]] * list[keys[j]] * list[keys[k]];
      }
    }
  }
  myout(output);
}

Measured memory_bytes: 27512
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

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

const ll MOD = 1000000007;


int main() {
	string s[3];
	cin >> s[0] >> s[1] >> s[2];
	cout << s[0][0] << s[1][1] << s[2][2] << endl;
	return 0;
}

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

using namespace std;

int A[400000],l=100000,r=100000-1,n;
int main()
{
	scanf("%d",&n); for(int i=1;i<=n;i++)
	{
		int k; scanf("%d",&k);
		if(i&1) A[++r]=k;
		else A[--l]=k;
	}
	if(n&1) for(int i=r;i>=l;i--) printf("%d ",A[i]);
	else for(int i=l;i<=r;i++) printf("%d ",A[i]);
	puts(""); return 0;
}

Measured memory_bytes: 2944
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        a = map(lambda x: int(x), sys.stdin.readline().split(" "))

        counters = [0, 0 ,0]
        for i in a:
            if i % 4 == 0:
                counters[2] += 1
            elif i % 2 == 0:
                counters[1] += 1
            else:
                counters[0] += 1

        if counters[0] > (counters[2] + 1):
            print("No")
        elif counters[0] == (counters[2] + 1):
            if counters[1] > 0:
                print("No")
            else:
                print("Yes")
        else:
            print("Yes")
            
        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 11320
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int N;
    vector<double> v;
    cin >> N;
    for (int i = 0; i < N; i++) {
        double temp = 0;
        cin >> temp;
        v.push_back(temp);
    }

    for (int i = 0; i < N - 1; i++) {
        sort(v.begin(), v.end());
        double sum = v[0] + v[1];
        v.erase(v.begin());
        v.erase(v.begin());
        v.push_back(sum / 2.0);
    }
    cout << fixed << setprecision(8);
    cout << v[0] << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String S = sc.next();

        System.out.println(solve(S) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(String S) {
        return S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5);
    }
}

Measured memory_bytes: 35588
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

ll n,a,b;
ll h[100010];
bool zenmetsu(ll m){
  ll k=upper_bound(h,h+n,b*m)-h;
  ll count=0;
  REP(j,k,n){
    count+=(h[j]-b*m+(a-b)-1)/(a-b);
  }
  if(count<=m)return true;
  else return false;
}

    int main(){
      cin >> n >> a >> b;
      rep(i,n)cin >> h[i];
      sort(h,h+n);
      ll ng=1;
      ll ok=(h[n-1]+b-1)/b;
     while(ok-ng>1){
      int mid=ng+(ok-ng)/2;
      if(zenmetsu(mid)){
        ok=mid;
      }else{
       ng=mid; 
      }
     }
      cout << ok << endl;
      return 0;}

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

int main() {
    int N, M, sum = 0, P, X;
    cin >> N;
    vector<int> T(N);
    rep(i, N) {
        cin >> T[i];
        sum += T[i];
    }
    cin >> M;
    rep(i, M) {
        cin >> P >> X;
        cout << sum - T[P - 1] + X << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;



int main(){

    int i=1,l,n;
    int sum=0;
    cin >> n >> l;

    while(i<n+1){
        sum+=l+i-1;
        i++;
    }

    if(l+n>0 && l<0){
        cout << sum << endl;
    }else if(l+n-1<0){
        cout << sum-(l+n-1) << endl;
    }else{
        cout << sum-l << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define pb push_back
#define ll long long
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fs(s) for(ll i=0;s[i]!='\0';i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define gcd(a,b) __gcd(a,b)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define c1(x) __builtin_popcountll(x)
#define setprs(x) cout << fixed << setprecision(x);
#define endl '\n'
const ll mod=1000000007;
const ll sz=2e5+100;
const double PI =3.14159265;
ll power(ll a, ll b, ll m = mod){if(b==0)return 1;else if(b==1)return a%m;else{ll t=power(a,b>>1,m);t=((t%m)*(t%m))%m;if(b&1)return ((t%m)*(a%m))%m;else return t%m;}}
 
//--------------------------------------------------------

void solve()
{
    double d,t,s;
    cin >> d >> t >> s;
    double time = d/s;
    if(time > t){
        cout << "No";
    }else{
        cout << "Yes";
    }

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

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




using namespace std;

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

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

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



void solve() {
    int n;
    cin >> n;
    vector<string> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            if (a[i] == a[j]) {
                cout << "No\n";
                return;
            }
        }
    }
    for (int i = 0; i + 1 < n; ++i) {
        if (a[i][a[i].size() - 1] != a[i + 1][0]) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}


//#define LOCAL

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



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


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



int main() {
  int n;
  cin >> n;
  int ac=0, wa=0, tle=0, re=0;
  rep(i,n){
    string s;
    cin >> s;
    if(s=="AC") ac++;
    else if(s=="WA") wa++;
    else if(s=="TLE") tle++;
    else re++;
  }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std ;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51} ;
int main(){
	int k ;
    cin >> k ;
    cout << a[k - 1] ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int n;
   std::cin >> n;
   std::vector<Int> xs(n), ys(n);
   rep(i,n) std::cin >> xs[i];
   rep(i,n) std::cin >> ys[i];
   std::vector<Int> xs2, ys2;
   Int t = 0;
   xs2.emplace_back(t);
   rep(i,n)
      t += xs[i], xs2.emplace_back(t);
   t = 0;
   ys2.emplace_back(t);
   rep(i,n)
      t += ys[i], ys2.emplace_back(t);
   Int res = 0;
   rep(i,n)
      res = std::max(res, xs2[i+1] - xs2[0] + ys2[n] - ys2[i]);
   printf("%ld\n", res);
}


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

ll tail(ll c){
  return c%10;
}

ll head(ll c){
  ll res = 1;
  while( res*10 <= c ){ res *= 10;}
  
  return c/res;
}



int main(){ 
  
 ll N; cin >> N;
  
  
  ll ans = 0;
  
   for(ll x = 1; x <= 9; x++){
    for(ll y = 1; y <= 9; y++){ 
      
      ll resa = 0; ll resb = 0;
      
      for(ll p = 1; p <= N; p++){ 
        // Aの先頭がxで末尾がyかを調べる
        if( head(p) == x && tail(p) == y ){ resa++;}
        if( head(p) == y && tail(p) == x){ resb++;}
        
      }
    
      ans += resa*resb;

      
    }
  }

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


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;
    cin>>N;
    vint A(N),B(N),C(N);
    rep(i,N)cin>>A[i];
    rep(i,N)cin>>B[i];
    rep(i,N)cin>>C[i];

    sort(all(A));sort(all(B));sort(all(C));

    vint dp(N);
    int cur=0;
    rep(i,N){
        while(cur<N&&B[i]>=C[cur])cur++;
        dp[i]=N-cur;
    }

    int sum=0;
    cur=N-1;
    int ans=0;
    for(int i=N-1;i>=0;i--){
        while(cur>=0&&B[cur]>A[i]){
            sum+=dp[cur];
            cur--;
        }
        ans+=sum;
    }

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


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

const double PI = 3.14159265358979;

class Point {
public:
    double x, y;
    Point(double x = 0.0, double y = 0.0) :x(x), y(y) {}
};

class Wind {
public:
    double w, a;
};

bool include(double angle, double low, double high) {
    if(low < 0.0) {
        double l = low + 2.0 * PI;
        if(l <= angle) return true;
    }
    if(high > 2.0 * PI) {
        double h = high - 2.0 * PI;
        if(angle <= h) return true;
    }
    return low <= angle && angle <= high;
}

bool savor(const Point &home, const Wind &wind, const vector<Point> &blossom, double d) {
    d /= 2.0;
    for(const auto &b: blossom) {
        Point dif(home.x - b.x, home.y - b.y);
        double angle = atan2(dif.y, dif.x);
        double dist = hypot(dif.y, dif.x);
        if(angle < 0.0) angle = angle + 2.0 * PI;
        if(dist <= wind.a && include(angle, wind.w - d, wind.w + d)) return true;
    }
    return false;
}

double toRadian(double d) {
    return d * PI / 180.0;
}

int main() {
    int H, R;
    while(cin >> H >> R, H | R) {
        vector<Point> home(H);
        for(auto &i: home) cin >> i.x >> i.y;

        int U, M, S;
        double du, dm, ds;
        cin >> U >> M >> S >> du >> dm >> ds;

        du = toRadian(du);
        dm = toRadian(dm);
        ds = toRadian(ds);

        vector<Point> plum(U), peach(M), cherry(S);
        for(auto &i: plum) cin >> i.x >> i.y;
        for(auto &i: peach) cin >> i.x >> i.y;
        for(auto &i: cherry) cin >> i.x >> i.y;

        vector<Wind> wind(R);
        for(auto &i: wind) cin >> i.w >> i.a;
        for(auto &i: wind) i.w = toRadian(i.w);

        // solve
        vector<int> number(H, 0);
        int maxNumber = 0;

        for(int i = 0; i < H; ++i) {
            for(int day = 0; day < R; ++day) {
                bool ok = savor(home[i], wind[day], {Point(0.0, 0.0)}, du);
                bool ng = false;
                ng |= savor(home[i], wind[day], plum, du);
                ng |= savor(home[i], wind[day], peach, dm);
                ng |= savor(home[i], wind[day], cherry, ds);

                if(!ok || ng) continue;

                ++number[i];
                maxNumber = max(maxNumber, number[i]);
            }
        }

        if(maxNumber) {
            bool first = true;
            for(int i = 0; i < H; ++i) if(number[i] == maxNumber) {
                if(!first) cout << " ";
                first = false;
                cout << i + 1;
            }
            cout << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
// make pair, tuple
// __gcd(int, int)
// bool isPrime(int n){
//       if(n <= 1)return false;
//       if(n <= 3)return true;
//       if(n % 2 == 0 || n % 3 == 0)return false;
//       for(int i = 5;i * i <= n;i += 6){
//             if(n % i == 0 || n % (i + 2) == 0)return false;
//       }
//       return true;
// }
// int countSubString(string s, string temp){
//       int ans = 0;
//       size_t f = s.find(temp);
//       while(f != string::npos){
//             ans++;
//             f = s.find(temp, f + 1);
//       }
//       return ans;
// }

int main(){
    char c;cin >> c;
    cout << char(c + 1);
}

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

public class Main {

    public static void main(String[] args) {
        try (InputReader in = new InputReader(); PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
            out.flush();
        }
    }

    void solve(InputReader in, PrintWriter out) {
        int a = in.nextInt();
        int b = in.nextInt();
        int ans = 0;
        for (int i = 0; i < 2; i++) {
            if (a > b) {
                ans += a;
                a--;
            } else {
                ans += b;
                b--;
            }
        }
        out.println(ans);
    }
}

class InputReader implements AutoCloseable {
    private final Scanner sc = new Scanner(System.in);

    String next() {
        return this.sc.next();
    }

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

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

    double nextDouble() {
        return Double.parseDouble(this.sc.next());
    }

    @Override
    public void close() {
        this.sc.close();
    }
}

Measured memory_bytes: 22356
from collections import Counter

n = int(input())
d_input=list(map(int,input().split()))
m=int(input())
t_input=list(map(int,input().split()))

d_count = Counter(d_input)
t_count = Counter(t_input)

for key,value in t_count.items():
    if key not in d_count:
        print('NO');exit()
    if d_count[key]<value:
        print('NO');exit()
print('YES')


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

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

	return 0;
}

Measured memory_bytes: 3632
// 2011/10/02 Tazoe

#include <iostream>
using namespace std;

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

	int G[100][100];
	for(int i=0; i<n; i++)
		for(int j=0; j<n; j++)
			if(i==j)
				G[i][j] = 0;
			else
				G[i][j] = -1;

	for(int i=0; i<n; i++){
		int r;
		cin >> r;
		int k;
		cin >> k;
		for(int j=0; j<k; j++){
			int t;
			cin >> t;
			G[r-1][t-1] = 1;
		}
	}
/*
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++)
			cout << G[i][j] << ' ';
		cout << endl;
	}
*/

	for(int k=0; k<n; k++)
		for(int i=0; i<n; i++)
			for(int j=0; j<n; j++)
				if(G[i][k]==-1||G[k][j]==-1)
					continue;
				else if(G[i][j]==-1||(G[i][j]>G[i][k]+G[k][j]))
					G[i][j] = G[i][k]+G[k][j];

	int p;
	cin >> p;

	for(int i=0; i<p; i++){
		int s, d, v;
		cin >> s >> d >> v;

		if(G[s-1][d-1]==-1){
			cout << "NA" << endl;
			continue;
		}

		if(v>=G[s-1][d-1]+1)
			cout << G[s-1][d-1]+1 << endl;
		else
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 0