akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int dp[3005][3005];

int main(){
    string s,t; cin >> s >> t;
    int ls = s.size(), lt = t.size();
    rep(i,ls){
        rep(j, lt){
            if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
            chmax(dp[i+1][j+1], dp[i+1][j]);
            chmax(dp[i+1][j+1], dp[i][j+1]);
        }
    }

    string ans = "";
    int i = ls, j = lt;
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i-1][j]) i--;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else {
            ans += s[i-1];
            i--; j--;
        }
    }
    reverse(ALL(ans));
    cout << ans << endl;
}


Measured memory_bytes: 35456
a,b,c=map(int,input().split())
d=[input() for i in range(a)]
e=[[0 for i in range(b)] for j in range(a)]
f=[[0]for i in range(a)]
n=0
for i in range(a):
  for j in range(b):
    if d[i][j]=="#":
      f[i][0]+=1
      f[i].append(j)
      n=i
t=1
s=0
for i in range(a):
  if f[i][0]==0:
    continue
  l=0
  for j in range(f[i][0]):
    for k in range(l,f[i][j+1]+1):
      for p in range(s,i+1):
        e[p][k]=t+j
    l=f[i][j+1]+1
    if j==f[i][0]-1:
      for k in range(l,b):
        for p in range(s,i+1):
          e[p][k]=t+j
  s=i+1
  if i==n:
    l=0
    for j in range(f[i][0]):
      for k in range(l,f[i][j+1]+1):
        for p in range(s,a):
          e[p][k]=t+j
      l=f[i][j+1]+1
      if j==f[i][0]-1:
        for k in range(l,b):
          for p in range(s,a):
            e[p][k]=t+j
    
  t+=f[i][0]
for i in range(a):
  print(" ".join(map(str,e[i])))

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

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

using namespace std;

int main(){
	int n,m; cin>>n>>m;
	vector<pair<int,int>> I[30];
	rep(i,n){
		int s,t,c; cin>>s>>t>>c; c--;
		I[c].emplace_back(s,t);
	}

	rep(c,m){
		sort(I[c].begin(),I[c].end());

		vector<pair<int,int>> J;
		int k=I[c].size();
		rep(i,k){
			if(i==k-1 || I[c][i].second!=I[c][i+1].first){
				J.emplace_back(I[c][i]);
			}
			else{
				I[c][i+1].first=I[c][i].first;
			}
		}
		I[c]=J;
	}

	int sum[100001]={};
	rep(c,m) for(auto J:I[c]) {
		sum[J.first]++;
		sum[J.second+1]--;
	}
	rep(i,100000) sum[i+1]+=sum[i];

	cout<<*max_element(sum,sum+100001)<<endl;

	return 0;
}


Measured memory_bytes: 1920
// DSL_1_A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

struct unionfind{
    vector<int> par;
    void init(int n){
        par.assign(n,-1);
    }
    int find(int x){
        if(par[x]<=-1) return x;
        else{
            par[x]=find(par[x]);
            return par[x];
        }
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(size(x)<size(y)) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
    }
    bool same_set(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return -1*par[find(x)];
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int n,q;
    cin>>n>>q;
    unionfind uf;
    uf.init(n);
    rep(i,q){
        int c,a,b;
        cin>>c>>a>>b;
        if(c==0){
            uf.unite(a,b);
        }else{
            bool ans=uf.same_set(a,b);
            cout<<(ans ? 1:0)<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int64_t L1 = 2,L2 = 1,L3;
  for(int i=0;i < N;i++){
    L3 = L2;
    L2 += L1;
    L1 = L3;
  }
  cout << L1 << endl;
}

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

typedef long long ll;

ll attack(ll h) {
  if(h == 1) {
    return 1;
  }
  ll half = h / 2;
  return attack(half) * 2 + 1;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h;
  cin >> h;
  cout << attack(h) << "\n";
  return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;
// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
int A,B,C; cin >> A >> B >> C;
if((A == B && A != C) || (B == C && B != A) || (C == A && C!= B)) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    let mut v = vec![];
    let mut sum = 0;
    for i in 0..n {
        let s = read::<u32>();
        sum += s;
        v.push(s);
    }
    if sum % 10 != 0 {
        println!("{}", sum);
        return;
    } else {
        v.sort();
        for m in v {
            if (sum - m) % 10 != 0 {
                println!("{}", sum - m);
                return;
            }
        }
    }
    println!("{}", 0);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
ps="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"
ps=ps.split(", ")
k=int(input())
print(ps[k-1])

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define vi vector<int>
#define vii vector<ll>
#define all(x) x.begin(),x.end()
#define mod 998244353
#define pb push_back
#define ii pair<int,int>
#define iii pair<ll,ll>
#define MAX 1000000000
typedef long long ll;
int main()
{
  ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
  int n; cin>>n;
  vii a(n),dp(n,0);
  f(i,0,n) cin>>a[i];
  dp[1]=abs(a[1]-a[0]);
  f(i,2,n) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
  cout<<dp[n-1]<<endl;
  return 0;
}


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

constexpr int MOD = 1000000007;
 // constexpr int MOD = 998244353;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  auto cs = [&](auto V) {
    int n = V.size() + 1;
    vector<long> R(n);
    for (int i = 1; i < n; i++) {
      R.at(i) = R.at(i - 1) + V.at(i - 1);
    }
    return R;
  };

  auto R = cs(A);
  long ans = 0;
  for (int i = 0; i < N; i++) {
    long tmp = R.at(N) - R.at(i + 1);
    tmp %= MOD;
    tmp *= A.at(i);
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    for (auto &&i : s) {
        if(i == '?') i = 'D';
    }
    cout << s << "\n";
    return 0;
}

Measured memory_bytes: 3748
#include <iostream>
#include<cmath>

using namespace std;

int main()
{
    long long n,x,y;
    cin>>n;
    if(n%2==0)
    { x=2;y=n/2;
        for(int  i=4;i<=sqrt(n);i++)
        {
            if(n%i==0&&((n/i)+i)<(x+y))
            {x=i;y=n/i;}}

    }
    else
    {
        x=1;y=n;
        for(int i=3;i<=sqrt(n);i++)
        {
            if(n%i==0&&((n/i)+i)<(x+y))
            {x=i;y=n/i;}
        }
    }cout<<x+y-2<<endl;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.IntSet as S
  
main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  print $ solve a b

solve :: Int -> Int -> Int
solve a b = case S.minView (S.intersection sa sb) of
  Nothing     -> -1
  Just (k, _) -> k
  where
    sa = S.fromList [ x | x <- [0 .. x0], floor (fromIntegral x * 0.08) == a ]
    sb = S.fromList [ x | x <- [0 .. x0], floor (fromIntegral x * 0.10) == b ]
    x0 = ceiling (101 / 0.08)

Measured memory_bytes: 508
import itertools
n, m, R = map(int, input().split())
r = list(map(int, input().split()))

d = [[10**7 for j in range(n)] for i in range(n)]
for i in range(m):
  a, b, c = map(int, input().split())
  a -= 1
  b -= 1
  d[a][b] = c
  d[b][a] = c

for i in range(n):
  d[i][i] = 0

for k in range(n):
  for i in range(n):
    for j in range(n):
      d[i][j] = min(d[i][k]+d[k][j],d[i][j])

# print (d)
ans = 10**8
for i in itertools.permutations(r):
  x = i
  k = 0
  for j in range(R-1):
    a,b = x[j+1],x[j]
    a -= 1
    b -= 1
    k += d[b][a]
  ans = min(ans,k)
print (ans)

Measured memory_bytes: 47064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int M = 10;
		List<long>[] L = new List<long>[M];
		for(int i=0;i<10;i++) L[i] = new List<long>();
		L[0].Add(3);
		L[0].Add(5);
		L[0].Add(7);
		
		for(int i=0;i<M-1;i++){
			foreach(var n in L[i]){
				L[i+1].Add(3 + n * 10);
				L[i+1].Add(5 + n * 10);
				L[i+1].Add(7 + n * 10);
			}
		}
		
		List<long> n357 = new List<long>();
		for(int i=0;i<M;i++){
			foreach(var n in L[i]){
				var hs = new HashSet<long>();
				var v = n;
				while(v > 0){
					hs.Add(v % 10);
					v /= 10;
				}
				if(hs.Count == 3) n357.Add(n);
			}
		}
		
		int cnt = 0;
		foreach(var n in n357){
			if(n <= N) cnt++;
		}
		Console.WriteLine(cnt);
		
		
		
	}
	long N;
	public Sol(){
		N = rl();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 20944
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

const int INF = 1e9;

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

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

  int dp[101010];
  fill(dp, dp + 101010, INF);
  dp[0] = 0; dp[1] = abs(h[0] - h[1]);

  for (int i = 2; i <= n; ++i) {
    for (int step = 1; step <= k; ++step) {
      if (i - step < 0) break;
      chmin(dp[i], dp[i - step] + abs(h[i] - h[i - step]));
    }
  }

  print(dp[n - 1]);

  return 0;
}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d,n,m;
    while(1){
    cin >> d;
    if(d==0)break;
    cin >> n >> m;
    vi ten,ordm;
    rep(i,0,n-1){
        int x;
        cin >> x;
        ten.pb(x);
    }
    rep(i,0,m){
        int x;
        cin >> x;
        ordm.pb(x);
    }
    ten.pb(0);
    ten.pb(d);
    sort(ALL(ten));
    sort(ALL(ordm));
    int ans=0,k=0;
    rep(j,1,ten.size()){
        //if(k==m)break;
        rep(i,k,m){
            if(ten[j]<ordm[i]){
                k=i;
                break;
            }
            //cout << ten[j]-ordm[i] << " " << ordm[i]-ten[j-1] << " " << i << endl;
            ans+=min(ten[j]-ordm[i],ordm[i]-ten[j-1]);
            if(i==(m-1)){
                k=m;
                break;
            }
           // else ans+=min(ten[j]-ordm[i]);
        }
    }
    cout << ans << endl;
    ten.clear();
    ordm.clear();
    }
    return 0;
}

Measured memory_bytes: 3892
# -*- coding:utf-8 -*-

def solve():
    N = int(input())
    As = list(map(int, input().split()))

    ans = [0 for _ in range(N)]

    for a in As:
        ans[a-1] += 1

    for a in ans:
        print(a)


if __name__ == "__main__":
    solve()


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

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

    //good luck kittu!
    int n, x; cin>>n;
    int need = 1, ans = 0;
    for(int i = 0; i<n; i++){
        cin>>x;
        if(x==need) need++;
        else ans++;
    }
    if(ans==n) return cout<<"-1\n", 0;
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    string s; cin >> s;
    vector<bool> A(26, false);
    for (int i = 0; i < s.length(); i++) {
        A[s[i] - 'a'] = true;
    }

    char ans = 'N';
    for (int i = 0; i < 26; i++) {
        if (!A[i]) {
            ans = 'a' + i;
            break;
        }
    }

    if (ans == 'N') {
        cout << "None" << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
int main() {
	string s; cin >> s;
	multiset<char> w;
	for (int i = 0; i < s.size(); i++)
		w.insert(s[i]);
	for (auto itr = w.begin(); itr != w.end(); itr++) {
		if (w.count(*itr) % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	//system("pause");
	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/agc002/tasks/agc002_b

n, m = map(int, input().split())

xy = []
for _ in range(m):
    x, y = map(int, input().split())
    xy.append((x - 1, y - 1))

box = [0] * n
box[0] = 1
num = [1] * n
for x, y in xy:
    if box[x]:
        box[y] |= 1
    num[x] -= 1
    num[y] += 1
    if not num[x]:
        box[x] = 0
ans = 0
for i in range(n):
    if box[i] and num[i]:
        ans += 1
print(ans)

Measured memory_bytes: 84200
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int X = Integer.parseInt(sc.next());
		int[] C = new int[N];
		int[][] A = new int[N][M];
		int cost = Integer.MAX_VALUE;
		for(int i = 0; i < N; i++) {
			C[i] = Integer.parseInt(sc.next());
			for(int j = 0; j < M; j++) {
				A[i][j] = Integer.parseInt(sc.next());
			}
		}
		sc.close();

		//ビット全探索
		//各参考書が2進数の各桁に一致
		for(int i = 0; i < (1 << N); i++) {
			int tmpCost = 0;
			int[] satisfaction = new int[M];
			for(int j = 0; j < N; j++) {
				//各参考書を買うか買わないかで条件分岐
				if((i >> j & 1) == 1) {
					tmpCost += C[j];
					for(int k = 0; k < M; k++) {
						satisfaction[k] += A[j][k];
					}
				}
			}
			boolean check = true;
			//各アルゴリズムの理解度の確認
			for(int j = 0; j < M; j++) {
				if(satisfaction[j] < X) {
					check = false;
				}
			}

			//コストの比較
			if(check) {
				cost = Math.min(cost, tmpCost);
			}
		}
		//答えを出力
		System.out.println(cost != Integer.MAX_VALUE ? cost : -1);
	}
}

Measured memory_bytes: 37184
from collections import defaultdict

def multi_input():
    return map(int, input().split())

N, M = multi_input()
AB = [list(multi_input()) for _ in range(N)]
d = defaultdict(int)

for value, num in AB:
    d[value] += num

ans = 0
for value, num in sorted(d.items(), key=lambda x:x[0]):
    ans += value * min(num, M)
    M -= num
    if M <= 0:
        break
print(ans)

Measured memory_bytes: 45692
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
elif x in c and y in c:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9124
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	int LEN = (int)1e6 + 1;
	void doIt() {
		int N = sc.nextInt();
		int[] X = new int[N];
		for(int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
		}
		/*int min = MAX;
		for(int i = 1; i <= 100; i++) {
			int sum = 0;
			for(int j = 0; j < N; j++) {
				sum += (X[j] - i) * (X[j] - i);
			}
			min = Math.min(min, sum);
		}
		System.out.println(min);*/
		int sum = 0;
		for(int i = 0; i < N; i++) {
			sum += X[i];
		}
		int avg = (int)Math.round((double)sum / N);
		sum = 0;
		for(int i = 0; i < N; i++) {
			sum += (X[i] - avg) * (X[i] - avg);
		}
		System.out.println(sum);
		
		
	}

	public static void main(String[] args) {
		new Main().doIt();
	}

}


Measured memory_bytes: 23380
N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
ans='No'

for i in range(N-M+1):
    for j in range(N-M+1):
        cnt=0
        if A[i][j:j+M] ==B[0]:
            for k in range(1,M):
                if A[i+k][j:j+M] == B[k]:
                    cnt+=1
            if cnt==M-1:
                ans='Yes'
                
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int n;cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<int> dp(n,1e+9);
  dp[0] = 0;
  rep(i,n){
    if( i + 2 < n ) dp[i+2] = min( dp[i+2] , dp[i] + abs(h[i] - h[i+2]) );
    if( i + 1 < n ) dp[i+1] = min( dp[i+1] , dp[i] + abs(h[i] - h[i+1]) );    
  }
  cout << dp[n-1] << "\n";
  return 0;
}


Measured memory_bytes: 1024
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)

const int maxn = 2e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

char x[maxn];
int dp[maxn];

void solve()
{
	cin >> (x + 1);
	int len = strlen(x + 1);
	dp[0] = 1;
	repp(i, 1, len)
	{
		if (i >= 5)
		{
			
			string t1 = "";
			t1 += x[i - 4];
			t1 += x[i - 3];
			t1 += x[i - 2];
			t1 += x[i - 1];
			t1 += x[i];
			if (t1 == "erase" || t1 == "dream")
			{
				dp[i] |= dp[i - 5];
			}
		}
		if (i >= 6)
		{
			string t1 = "";
			t1 += x[i - 5];
			t1 += x[i - 4];
			t1 += x[i - 3];
			t1 += x[i - 2];
			t1 += x[i - 1];
			t1 += x[i];
			if (t1 == "eraser" )
			{
				dp[i] |= dp[i - 6];
			}
		}
		if (i >= 7)
		{
			string t1 = "";
			t1 += x[i - 6];
			t1 += x[i - 5];
			t1 += x[i - 4];
			t1 += x[i - 3];
			t1 += x[i - 2];
			t1 += x[i - 1];
			t1 += x[i];
			if (t1 == "dreamer")
			{
				dp[i] |= dp[i - 7];
			}
		}
	}
	if (dp[len])
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
}

int main()
{

	solve();
	//ios_base::sync_with_stdio(false);
	return 0;
}

Measured memory_bytes: 896
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n >> d;
	for(i=0;i<n;i++) {
		cin >> x >> y;
		a = x*x + y*y;
		if (a <= d*d) ans++;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    int N;
    cin >> N;
    vi f(N + 1, 0);
    int v = 1000;
    for (int j = 1; j <= v; j++)
    {
        for (int k = 1; k <= v - j; k++)
        {
            for (int l = 1; l <= v - j - k; l++)
            {
                int c = j * j + k * k + l * l + j * k + k * l + l * j;
                if (c <= N)
                {
                    f[c]++; 
                }
            }
        }
    }

    for (int i = 1; i <= N; i++)
    {
        cout << f[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3584
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

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

	vector<llong> a(n);
	int minus = 0;
	ullong s = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
		if (a.at(i) <= 0)
		{
			minus++;
			a.at(i) *= -1;
		}

		s += a.at(i);
	}

	
	if (minus % 2 != 0)
	{
		sort(a.begin(), a.end());
		s -= 2 * a.front();
	}

	cout << s << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define Rint register int
#define C(n,m) (n<m?0:1ll*fac[n]*invfac[n-m]%mod*invfac[m]%mod)
using namespace std;
int T,n,m,p,k,head[100010],o=0,sz,ed,cnt[3],c[100010];
bool can,vis[100010];
struct edge{
	int to,link,w;
}e[200010];
void add_edge(int u,int v){
	e[++o].to=v,e[o].link=head[u],head[u]=o,e[o].w=1;
	e[++o].to=u,e[o].link=head[v],head[v]=o,e[o].w=2;
}
void dfs(int u,int col){
	cnt[col]++;vis[u]=true;c[u]=col,sz++;
	for(int i=head[u];i;i=e[i].link){
		if(e[i].w==1) ed++;
		if(vis[e[i].to]){
			if(c[e[i].to]!=(col+e[i].w)%3) can=false;
			continue;
		}
		dfs(e[i].to,(col+e[i].w)%3);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1,u,v;i<=m;i++) scanf("%d%d",&u,&v),add_edge(u,v);
	long long ans=0;
	for(int i=1;i<=n;i++){
		if(vis[i]) continue;
		sz=ed=cnt[0]=cnt[1]=cnt[2]=0;can=true;
		dfs(i,0);
		if(!can) ans+=1ll*sz*sz;
		else{
			if(!min(min(cnt[0],cnt[1]),cnt[2])) ans+=ed;
			else ans+=1ll*cnt[0]*cnt[2]+1ll*cnt[0]*cnt[1]+1ll*cnt[1]*cnt[2];
		}
	}
	printf("%lld\n",ans); 
}


Measured memory_bytes: 11676
#include <iostream>
#include <vector>
#include <string>
using namespace std;

int n, num['Z'-'A'+2];
char c[101];

int main() {
	vector<string>vec;

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

		for (int i = 1; i <= n; i++) {
			cin >> c[i];
		}

		int i;
		for (i = 1; i <= n; i++) {
			num[c[i] - 'A' + 1]++;
			//cout << "c[" << i << "];" << (c[i] - 'A') << endl;

			/*cout << "i:" << i << " ";
			for (int j = 1; j <= 'Z' - 'A' + 1; j++) {
				cout << num[j] << " ";
			}
			cout << endl;*/

			int first = 0, second = 0;
			for (int j = 1; j <= 'Z'-'A'+1; j++) {
				if (num[j] >= num[first]) {
					second = first;
					first = j;
				}
				else if (num[j] > num[second]) {
					second = j;
				}
			}
			if (num[first] - num[second] > n - i || i == n) {
				break;
			}
		}

		int first = 0, second = 0;
		for (int j = 1; j <= 'Z'-'A'+1; j++) {
			if (num[j] >= num[first]) {
				second = first;
				first = j;
			}
			else if (num[j] > num[second]) {
				second = j;
			}

			//cout << "first:" << first << " second:" << second << endl;
			//cout << "num[first]:" << num[first]<< " num[second]:" << num[second] << endl;
		}

		if (num[first] > num[second]) {
			//cout << (char)(first - 1 + 'A') << " " << i << endl;
			string ans = "";
			ans.push_back((char)(first - 1 + 'A'));
			ans.push_back(' ');
			ans += to_string(i);
			vec.push_back(ans);
		}
		else {
			//cout << "TIE" << endl;
			vec.push_back("TIE");
		}

		for (int j = 1; j <= 'Z' - 'A' + 1; j++) {
			num[j] = 0;
		}
	}

	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << endl;
	}

}


Measured memory_bytes: 3244
#include <iostream>
#include <stdio.h>
using namespace std;
const int UP=0;
const int FLOMT=1;
const int RIGHT=2;
const int LEFT=3;
const int BACK=4;
const int DOWN=5;
class Dice{
 public:
  Dice();~Dice();
  int num[6];
  void set_num(int n,int i);
  void spin(char c);
  int get_num(int n);
};
Dice::Dice(){}
Dice::~Dice(){}
void Dice::set_num(int n,int i){num[i]=n;}
int Dice::get_num(int n){return num[n];}
void Dice::spin(char c){
  int temp;
  if(c=='S'){
    temp=num[0];
    num[0]=num[4];
    num[4]=num[5];
    num[5]=num[1];
    num[1]=temp;
  }if(c=='N'){
    temp=num[0];
    num[0]=num[1];
    num[1]=num[5];
    num[5]=num[4];
    num[4]=temp;
  }if(c=='W'){
    temp=num[0];
    num[0]=num[2];
    num[2]=num[5];
    num[5]=num[3];
    num[3]=temp;
  }if(c=='E'){
    temp=num[0];
    num[0]=num[3];
    num[3]=num[5];
    num[5]=num[2];
    num[2]=temp;
  }
}
 
int main(){
  char c[102];
  Dice *m_Dice;
  m_Dice=new Dice;
  for(int i=0; i<6; i++){
    int n;
    cin>>n;
    m_Dice->set_num(n,i);
  }
  cin>>c;
  for(int i=0; i<102; i++){
    if(c[i]!='\0')m_Dice->spin(c[i]);
    else break;
  }
  cout<<m_Dice->get_num(0)<<endl;
  delete m_Dice;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }


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

    ll A, B; cin >> A >> B;
    cout << ((A>9||B>9)?-1:A*B) << '\n';
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool is_zero(char str[]) //文字列に０のみが入力された時にtrueを返す
{
    if (str[0] == '0' && str[1] == '\0')
    {
        return true;
    }
    return false;
}
int value_number(char n) //その数字文字をint型の整数で表した時の値
{
    return n - '0';
}
int add_number(char str[]) //各数字文字を全部足す
{
    int add = 0;
    int len = strlen(str);
    for (int i = 0; i < len; i++)
    {
        add += value_number(str[i]);
    }
    return add;
}

int main(void)
{
    char str[1000]; //何行入力されるかは指定されていなかったので、マクロで３００にした。

    while (1)
    {
        scanf("%s", str);
        if (is_zero(str)) //終了条件。
        {
            break;
        }
        //whileを抜けた時点でのiは、最終行を含まない行数に等しい(０から始まっているので、ループした回数的には i + 1 だけど)

        printf("%d\n", add_number(str));
    }

    return 0;
}



Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
const   int MaxN=5005;
const   int base=1000000007;
int n,a[MaxN][MaxN],m;
typedef long long ll;
ll f[MaxN][MaxN];

void Xuli()
{
    f[1][1]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            if (!(i==1 && j==1) && a[i][j]==1)
                f[i][j]=(f[i-1][j]+f[i][j-1])%base;
    cout<<f[n][m];
}

int main()
{
    //scanf("%d%d",&n,&m);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        for(int j=0;j<s.length();j++)
            if (s[j]=='.') a[i][j+1]=1;
    }
    Xuli();
}


Measured memory_bytes: 62336
#include <stdio.h>
#include <vector>

int main() {
  int n;
  int p[4][3][10];
  int b, f, r, v;

  int i, j, k;
  for(i = 0; i < 4; i++) {
    for(j = 0; j < 3; j++) {
      for(k = 0; k < 10; k++) {
        p[i][j][k] = 0;
      }
    }
  }

  scanf("%d", &n);
 
  char nl;
  for(i = 0; i < n; i++) {
    scanf("%d %d %d %d%c", &b, &f, &r, &v, &nl);
    p[b - 1][f - 1][r - 1] += v;
  }

  for(i = 0; i < 4; i++) {
    for(j = 0; j < 3; j++) {
      for(k = 0; k < 10; k++) {
        printf(" %d", p[i][j][k]);
      }
      printf("\n");
    }
    if(i < 3) {
      for(k = 0; k < 10; k++) {
        printf("##");
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 2660
from collections import deque
INFTY = 10**10
N,M = map(int,input().split())
ind = 2
if N==1:
    ind = 0
else:
    G = {}
    for _ in range(M):
        L,R,D = map(int,input().split())
        if L not in G:
            G[L]=[]
        G[L].append((R,D))
        if R not in G:
            G[R] = []
        G[R].append((L,-D))
    dist = [INFTY for _ in range(N+1)]
    hist = [0 for _ in range(N+1)]
    for i in G:
        ind = 2
        heap = deque([i])
        while heap:
            cur = heap.popleft()
            if hist[cur]==0:
                dist[cur] = 0
                hist[cur]=1
                ind = 0
            elif hist[cur]==1 and ind==2:
                break
            for x in G[cur]:
                v,w = x[0],x[1]
                if hist[v]==0:
                    dist[v] = dist[cur]+w
                    heap.append(v)
                    hist[v]=1
                else:
                    if dist[v]!=dist[cur]+w:
                        ind = 1
                        break
            if ind==1:break
        if ind==1:break
if ind!=1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 72436
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 231548613323;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}
 
ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);
	t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
 
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
 
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}
 
ll rev(ll v){
	return mpow(v,MOD-2);
}
 
void solve(){
	ll n;
	cin >> n;
	ll k,s;
	cin >> k >> s;
	forn(i,k) cout << s << " ";
	forn(i,n-k){
		if(s==1e9) cout << 1 << " ";
		else cout << s+1 << " ";
	}
	cout << ln;
}
 
int main()
{
	fast_cin();
    ll t=1;
    // cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
ll INF = 1001001001;
ll gcd(int a, int b) {return b ? gcd(b, a%b):a;}
ll lcm(int a, int b) {return a/gcd(a, b)*b;}
int main() {
  ll A, B, C, D; cin >> A >> B >> C >> D;
  ll count_1=0, count_2=0, count_3=0, count_4=0, count_5=0, count_6=0, tmp_1=0, tmp_2=0;
count_1 = B/C; count_2=B/D; count_3=B/lcm(C, D);
  tmp_1 = count_1+count_2-count_3;
count_4 = (A-1)/C; count_5 = (A-1)/D; count_6 = (A-1)/lcm(C, D);
  tmp_2 = count_4+count_5-count_6;
  ll ans = (B-A+1) - (tmp_1 - tmp_2);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=205;
ll a[N],b[65];
char s[N];
int n;

void rmain(){
	read(n);
	rep(i,1,n) read(a[i]);
	scanf("%s",s+1);
	memset(b,0,sizeof b);
	per(i,n,1){
		ll x=a[i];
		if(s[i]=='1'){
			per(j,60,0){
				if(x>>j&1){
					x^=b[j];
				}
			}
			if(x){
				puts("1");
				return;
			}
		}
		else{
			per(j,60,0){
				if(x>>j&1){
					if(b[j]){
						x^=b[j];
					}
					else{
						b[j]=x;
						break;
					}
				}
			}
		}
	}
	puts("0");
}

int main(){
	int T; read(T);
	while(T--) rmain();
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int main(){
  int A, B, cnt=0;
  cin >> A >> B;

  for (int i=A; i<=B; i++) {
    int t=i, rev=0;
    while (t) {
      rev*=10;
      rev+=t%10;
      t/=10;
    }
    if (i==rev) cnt++;
  }

  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n;
    cin >> n;
    vint h(n);
    rep(i, n) cin >> h[i];
    int l = h[0];
    int now = 0;
    int ans = 0;
    rep(i, n - 1)
    {
        if (l >= h[i + 1])
            now++;
        else
            now = 0;

        ans = max(ans, now);
        l = h[i + 1];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    
    vector<vector<long long>> dp(N+1, vector<long long>(H+1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H; ++j) {
            chmin(dp[i+1][j], dp[i][j]);
            chmin(dp[i+1][min(j+A[i], H)], dp[i+1][j] + B[i]);
        }
    }
    cout << dp[N][H] << endl;
}


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

int main() {
  int N;
  cin>>N;
  vector<int> a(N);
  vector<int> z(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i)>>z.at(i);
  }
  sort(a.begin(), a.end());
  sort(z.begin(), z.end());
  if(N%2==1){
    cout<<1+z.at(N/2)-a.at(N/2)<<endl;
  }
  else{
    cout<<1+z.at(N/2)-a.at(N/2)+z.at(N/2-1)-a.at(N/2-1)<<endl;
  }
}

Measured memory_bytes: 4852
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <complex>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef pair<int, int> P;

int H, W;
vector<int> X, Y;
vector<vector<int> > G;
vector<bool> used;

void make_edge(const map<int, vector<int> > &same){
  FOREACH(it, same){
    vector<int> vi = it->second;
    REP(i, vi.size() - 1){
      int u = vi[i], v = vi[i+1];
      G[u].push_back(v);
      G[v].push_back(u);
    }
  }  
}

int dfs(int v, vector<bool> &E){
  used[v] = true;
  if(X[v] == 1) E[0] = true;
  if(X[v] == W) E[1] = true;
  if(Y[v] == 1) E[2] = true;
  if(Y[v] == H) E[3] = true;

  int res = 1;
  REP(i, G[v].size()){
    int to = G[v][i];
    if(!used[to]){
      res += dfs(to, E);
    }
  }
  return res;
}

int main(){
  int N;
  cin >> N >> W >> H;
  G.resize(N);
  
  map<int, vector<int> > samex, samey;
  
  REP(i, N){
    int x, y;
    cin >> x >> y;
    X.push_back(x);
    Y.push_back(y);
    samex[X[i]].push_back(i);
    samey[Y[i]].push_back(i);
  }
  
  make_edge(samex);
  make_edge(samey);
  
  int res = 0;
  int con = 0;
  vector<int>  C(4, 0);  
  used.resize(N, false);
  
  REP(i, N)if(!used[i]){
    vector<bool> E(4, false);
    res += dfs(i, E) - 1;
    REP(j, E.size()){
      C[j] += E[j];
    }
    con++;
  }
  
  if(con > 1){
    res += 2 * con - *max_element(ALL(C)) - 1;
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 10328
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    int M, K;
    cin >> M >> K;
    if(K >= pow(2, M)) {
        cout << -1 << endl;
    } else if(M == 1 && K == 1) { 
        cout << -1 << endl;
    }else if(K == 0) {
        REP(i, pow(2, M) - 1) {
            cout << i << " " << i << " ";
        }
        cout << pow(2, M) - 1 << " " << pow(2, M) - 1 << endl;
    } else {
        REP(i, pow(2, M))
            if(i != K) cout << i << " ";
        cout << K << " ";
        FORR(i, pow(2, M) - 1, 0)
            if(i != K) cout << i << " ";
        cout << K << endl;
    }
    return 0;
}

Measured memory_bytes: 4180
N = int(input())
X_list = [int(i) for i in input().split()]

low = min(X_list)
high = max(X_list)

minimum = 99999999999999
for p in range(low,high) :
    tmp = 0
    for x in X_list :
        tmp += pow(x-p,2)
    
    if (tmp < minimum) :
        minimum = tmp

if (minimum == 99999999999999) :
    print(0)
else :
    print(minimum)

Measured memory_bytes: 3064
import sys
r=lambda:sys.stdin.readline().strip()
while 1:
 n=int(r())
 if n==0:break
 d={}
 for _ in[0]*n:
  k,v=r().split()
  d[k]=v
 a=''
 for _ in[0]*int(r()):
  e=r()
  a+=d[e]if e in d else e
 print(a)


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  string s,t; cin>>s>>t;
  int flag = 0;
  rep(i,(int)s.size())if(s.at(i)!=t.at(i))flag =1;
  if(!flag)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 3600
// https://atcoder.jp/contests/abc128/tasks/abc128_c

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<string, int> PSI;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int n, m;
vector<unsigned int> vi; // 入力値のビット列（例：1, 3なら101）
vector<unsigned int> vp; // ビット列の総和の偶数・奇数
bool check(unsigned int arg) {
    int ans = 0, cnt;
    bool flag = true;
    // スイッチが未接続なら点灯しない
    // if (arg == 0)
    //     return false;
    // 全部のスイッチで点灯するか確認
    REP(i, m) {
        cnt = __builtin_popcount(vi[i] & arg);
        if (cnt % 2 != vp[i]) {
            flag = false;
            break;
        }
    }
    return flag;
}
int ok(int arg) {
    for (int i = 0; i < m; ++i) {
        int cnt = 0;
        cnt = __builtin_popcount(vi[i] & arg);
        if (vp[i] != (cnt & 1))
            return false;
    }
    return true;
}
int dfs(int idx, unsigned int arg) {
    if (idx == n) {
        return check(arg);
    }
    int ans = dfs(idx + 1, arg);
    arg |= (1 << idx); // nビット目を1にする
    ans += dfs(idx + 1, arg);
    return ans;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    vi.resize(m);
    vp.resize(m);
    REP(i, m) {
        int k, l;
        cin >> k;
        // 入力値をビット列にする（例：1, 3なら101）
        unsigned int t = 0;
        REP(j, k) {
            cin >> l;
            t |= (1 << (--l));
        }
        vi[i] = t;
    }
    REP(i, m) { cin >> vp[i]; }
    cout << dfs(0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    int n = N;
    int sum = 0;
    for(;;){
        int r = n % 10;
        sum += r;
        if(n/10 == 0){
            break;
        }
        n = n / 10;
    }

    if(N % sum == 0){
        cout << "Yes" << endl;
    } else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
  int n;
  cin>>n;
  if(n==2){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
      cout<<fixed<<setprecision(10);
  cout<<sqrt((c-a)*(c-a)+(d-b)*(d-b));
    return 0;
  }
  vector<int> vec(2*n);
  for(int i=0;i<2*n;i++){
    cin>>vec.at(i);
  }
  int a,b,c,d;
  double f=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      a=vec.at(2*i);
      b=vec.at(2*j);
      c=vec.at(2*i+1);
      d=vec.at(2*j+1);
      f+=sqrt((b-a)*(b-a)+(d-c)*(d-c));
    }
  }
  cout<<fixed<<setprecision(10);
  cout<<f/n;
}

Measured memory_bytes: 256