akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

vector<pair<ll, ll>> factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; (i * i) <= n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while((n % i) == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b;
    cin >> a >> b;
    ll g = __gcd(a, b);
    auto fac = factorize(g);
    set<ll> yak;
    yak.insert(1);
    rep(i, sz(fac)) {
        rep(j, fac[i].second) {
            set<ll> add;
            for(auto x : yak) add.insert(x * fac[i].first);
            for(auto x : add) yak.insert(x);
        }
    }
    set<ll> ans;
    for(auto x : yak) ans.insert(x);
    for(auto x : yak) {
        if (ans.count(x) == 0) continue;
        for(auto it = ans.begin(); it != ans.end(); ) {
            if (x == *it) {
                it++;
                continue;
            }
            if (__gcd(x, *it) != 1) {
                ans.erase(it++);
            }
            else {
                it++;
            }
        }
    }
    cout << sz(ans) << endl;
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int k,l;
  k = 0;
  l = s.length();
  if(l%2==0){
  for(int i=0;i<(int)l/2;i++){
    if(s[i] == s[l-1-i]){
    }
    else{
      s[l-i-1] = s[i];
      k++;
    }
  }
  }
  else{
      for (int i=0;i<(int)(l+1)/2;i++){
          if(s[i] == s[l-i-1]){
    }
    else{
      s[l-i-1] = s[i];
      k++;
    }
  }
      }
  
  cout<<k<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException
	{
		int[] n = new int[65535];
		int i=0,j;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		while(true)
		{
			n[i] = Integer.parseInt(br.readLine() );

			if(n[i]==0) break;
			else i++;
		}

		for(j=0; j<i; j++) System.out.println("Case " + (j+1) + ": " + n[j]);

	}
}

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

int main() {
	int N;
	cin >> N;
	int cnt = 0;
	for(int i=1; i<=N; i++) {
		if(i % 2 != 0) {
			cnt++;
		}
	}
	double p = (double)cnt / N;
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 256
i=0,j,a[10],y;main(){for(;i<=9;)scanf("%d",&a[i++]);for(i=0;i<=8;i++)for(j=i+1;j<=9;j++){if(a[i]<a[j]){y=a[i];a[i]=a[j];a[j]=y;}}for(i=0;i<3;)printf("%d\n",a[i++]);exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long MOD = 1000000007;

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

	int n;
	cin >> n;
	set<ll> a;
	rep(i, n) {
		ll t;
		cin >> t;

		auto p = a.find(t);

		if (p == a.end()) {
			a.insert(t);
		}
		else {
			cout << "NO" << "\n";
			return 0;
		}
	}

	cout << "YES" << "\n";

	return 0;
}


Measured memory_bytes: 9600
li = []
while True:
  l = input()
  a, b = list(map(int,l.split()))
  if a ==0 and b == 0:
    break
  else:
    if a > b :
      a,b = b,a
  li.append(f'{a} {b}') 

for j in li:
  print(j)




Measured memory_bytes: 5884
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
ll MM = 1000000000; ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
int dh[4] = {-1, 0, 0, 1};
int dw[4] = {0, -1, 1, 0}; 
using P = pair<int, int>;
const double pi = acos(-1.0);

using Graph = vector<vector<ll>>;

int main(){
  int n;
  cin>>n;
  vector<pair<ll,ll>>p(n);
  rep(i,n)cin>>p[i].first>>p[i].second;
  vector<ll>plus(n);
  vector<ll>mins(n);
  rep(i,n){
    plus[i]=p[i].first+p[i].second;
    mins[i]=p[i].first-p[i].second;
  }
  sort(all(plus));
  sort(all(mins));
  ll ans=max(abs(plus[0]-plus[n-1]),abs(mins[0]-mins[n-1]));
  cout<<ans<<endl;
    
    
  return 0;
}


Measured memory_bytes: 9588
module DoublyLinkedList = struct
  type t = {
    mutable data : int;
    mutable next : t;
    mutable prev : t;
  }

  let make () =
    let rec head = { data = 0; next = head; prev = head } in
    head

  let insert data head =
    let x = { data = data; next = head.next; prev = head } in
    head.next.prev <- x;
    head.next <- x

  let delete x =
    x.next.prev <- x.prev;
    x.prev.next <- x.next

  let delete_first head = delete head.next

  let delete_last head = delete head.prev

  let delete_node data head =
    let rec doit ite =
      if ite == head then None
      else if ite.data = data then Some ite
      else doit ite.next
    in
    match doit head.next with
    | None -> ()
    | Some ite -> delete ite

  let iteri head ~f =
    let rec doit i ite =
      if ite == head then ()
      else (f i ite.data; doit (i + 1) ite.next)
    in
    doit 0 head.next
end

module L = DoublyLinkedList

let () =
  let n = read_int () in
  let head = L.make () in
  let rec read i =
    if i >= n then ()
    else begin
      match Str.split (Str.regexp " ") (read_line ()) with
      | ["insert"; n] -> (L.insert (int_of_string n) head; read (i + 1))
      | ["delete"; n] -> (L.delete_node (int_of_string n) head; read (i + 1))
      | ["deleteFirst"] -> (L.delete_first head; read (i + 1))
      | ["deleteLast"] -> (L.delete_last head; read (i + 1))
      | _ -> exit 1
    end
  in
  read 0;
  L.iteri head ~f:(fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n);
  print_newline ()

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

struct Card {
	char c;
	int v;
};

int BubbleSort(vector<Card>& C, int N) {
    bool flag = true;
    int cnt = 0;
    int i = 0;
    while (flag) {
        flag = false;
        for (int j = N-1; j > i; j--) {
            if (C[j-1].v > C[j].v) {
                Card tmp = C[j-1];
                C[j-1] = C[j];
                C[j] = tmp;
                flag = true;
                cnt++;
            }
        }
        i++;
    }
    return cnt;
}

int SelectionSort(vector<Card>& C, int N) {
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int minj = i;
		for (int j = i; j < N; j++) {
			if (C[j].v < C[minj].v) {
				int tmp = minj;
				minj = j;
				j = tmp;
			}
		}
		if (C[i].v != C[minj].v) {
			Card tmp = C[i];
			C[i] = C[minj];
			C[minj] = tmp;
		}
	}
	return cnt;
}

bool isSame(Card& a, Card& b) {
	return a.c == b.c && a.v == b.v;
}

bool isStable(vector<Card>& in, vector<Card>& out, int N) {
	for (int i = 0; i < N; i++) {
		for (int j = i+1; j < N; j++) {
			for (int a = 0; a < N; a++) {
				for (int b = a+1; b < N; b++) {
					if (in[i].v == in[j].v && isSame(in[i], out[b]) && isSame(in[j], out[a])) {
						return false;
					}
				}
			}
		}
	}
	return true;
}

void show(vector<Card>& card, int N) {
	for (int i = 0; i < N; i++) {
		if (i < N-1) cout << card[i].c << card[i].v << ' ';
		else cout << card[i].c << card[i].v << endl;
	}
}

int main() {
	int N;
	cin >> N;
	vector<Card> in(N);
	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;
		in[i].c = (char)str[0];
		in[i].v = str[1] - '0';
	}

	vector<Card> out = in;
	BubbleSort(out, N);
	show(out, N);
	if (isStable(in, out, N)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;

	vector<Card> out2 = in;
	SelectionSort(out2, N);
	show(out2, N);
	if (isStable(in, out2, N)) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
}



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

#define ll long long
#define ii pair<int, int>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000000

using namespace std;
#define prime 1000000007

const ll N = 300005;

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int a, p;

int ce(int a, int b){
	return (a+b-1)/b;
}

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

	printf("%d\n", (3*a + p)/2);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
	int n, m; cin >> n >> m;
	cout << (n-1) * (m-1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int const maxn=1e5+5;
char s[maxn];
int a[maxn],b[maxn];
int main()
{
    scanf("%s",&s);
    int n=strlen(s);
    if(n%2==0)
    {
        int l=n/2-1;
        int r=n/2;
        int res=n/2;
        while(r<n&&l>=0&&s[l]==s[r])
        {
            l--;
            r++;
            res++;
        }
        printf("%d\n",res);
    }
    else
    {
        int l=n/2-1;
        int r=n/2+1;
        int res=n/2+1;
        if(s[n/2]!=s[l]||s[n/2]!=s[r])
        printf("%d\n",res);
        else
        {
            while(r<n&&l>=0&&s[l]==s[r])
          {
            l--;
            r++;
            res++;
           }
           printf("%d\n",res);
        }
    }
    return 0;
}

Measured memory_bytes: 256
a=int(input())
slis=[a]
for i in range(2,1000001):
	if a%2==0:
		a=a/2
		slis.append(int(a))
	elif a%2!=0:
		a=3*a+1
		slis.append(int(a))
	if slis.count(a)==2:
		print(i)
		break

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

int main(){
int x,y,z;
int a,b,c;

cin >> x >> y >> z;

if(x < y){
a = x;
b= y;
}else{
a = y;
b= x;
}
if(b < z){
c=z;
}else if(a > z){
c=b;
b=a;
a=z;
}else{
c=b;
b=z;
}

cout << a << " " << b  << " " << c << endl;
return 0;

}

Measured memory_bytes: 1164
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n,m,q;
	cin>>n>>m>>q;
	int out=0,mi=inf;
	vi a(n),b(m);
	rep(i,n)cin>>a[i],cmin(mi,a[i]);
	out+=mi;
	mi=inf;
	rep(i,m)cin>>b[i],cmin(mi,b[i]);
	out+=mi;

	rep(i,q){
		int x,y,z;
		cin>>x>>y>>z;
		cmin(out,a[x-1]+b[y-1]-z);
	}
	cout<<out<<endl;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> board(H+2, vector<char>(W+2, 'x'));
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      char a;
      cin >> a;
      board[i][j]=a;
    }
  }
  string ans="No";
  bool finish=false;
  int dy[4]={-1, 0, 1, 0}, dx[4]={0, 1, 0, -1};
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(board[i][j]=='.') continue;
      for(int k=0; k<4; k++){
        int y=dy[k], x=dx[k];
        if(board[i+y][j+x]=='#') break;
        if(k==3) finish=true;
      }
    }
    if(finish) break;
    if(i==H) ans="Yes";
  }
  cout << ans << endl;
}



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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    int n;
    cin >> n;
    cout << n * (n + 1) / 2 << endl;

    return 0;
}



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

int main(){
  string s, t;
  cin >> s >> t;
  int cnt = 0;
  for (int i = 0; i < 3; i++){
      if (s[i] == t[i])
        cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
//#include <cstdio>
//#include <cstdlib>
//#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

int main(void){

	int height[20];
	
	for(int i=0;i<10;i++){
		cin >> height[i];
	}
	
	sort(height, height + 10, greater<int>());
	
	for(int i=0;i<3;i++){
		cout << height[i] << endl;
	}
	

	return 0;
}

/*
for(i=0;i<N;i++){
	cin >> X[i];
}


for(i=0;i<N;i++){
	for(j=0;j<N;j++){
		cin >> X[i][j];
	}
}
*/

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

int main() {
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  string ans = "APPROVED";
  for(int i = 0; i < n; i++) {
    if(a[i] % 2 == 0 && a[i] % 3 != 0 && a[i] % 5 != 0) {
      ans = "DENIED";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ms(x, n) memset(x,n,sizeof(x));
typedef  long long LL;
const int INF = 1 << 30;
const int MAXN = 110;

int n, d[MAXN];
int main() {
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> d[i];
    int ans = 0;
    for(int i = 2; i <= n; ++i)
        for(int j = 1; j < i; ++j)
            ans += d[i]*d[j];
    cout << ans << endl;


    return 0;
}


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

int main() {
    int n, m, total=0, passed=0;
    cin >> n >> m;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
        total += a.at(i);
    }
    for (int i=0; i<n; i++) {
        int comp = total/(4*m);
        if (total%(4*m) != 0) {
            comp++;
        }
        if (a.at(i) >= comp) {
            passed++;
        }
    }
    if (passed >= m) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
A, B = map(int, input().split())
tmp = [A, A^B, A-1, (A^B)-1]
tmp2 = [B, 1, B+1, 0]
# ans = A
# for i in range(A+1, B+1):
#     ans ^= i
# print(ans)
ans = 0
r = abs(A-B) % 4
# print(r)
if A % 2 == 1:
    # 左, A^B, 左-1, A^B-1
    ans = tmp[r]
else:
    # 右, 1, 右+1, 0
    ans = tmp2[r]
# print(abs(A-B)%4)
# print(r)
# print(A^B)
print(ans)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

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

typedef pair<int, int> pii;
typedef long long ll;


const int BIG_NUM = 1e8;
const ll INF = 1000000000000000000;

const int ALPHABET = 26;

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s0(h);
	for (int i = 0; i < h; i++) {
		cin >> s0[i];
	}

	ll ans = 0;

	for (int bh = 0; bh < (1 << h); bh++) {
		vector<string> s1(s0);

		for (int i = 0; i < h; i++) {
			if (((bh >> i) & 1) == 1) {
				s1[i] = string('.', w);
			}
		}


		for (int bw = 0; bw < (1 << w); bw++) {
			int cnt = 0;



			for (int i = 0; i < w; i++) {
				if (((bw >> i) & 1) == 0) {
					for (int j = 0; j < h; j++) {
						if (s1[j][i] == '#') {
							cnt++;
						}
					}
				}
			}

			if (cnt == k) {
				ans++;

				
			}

		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int n, m, q;
int a[101], b[101], c[101], d[101];
int ans;
void DFS(vector<int> v, int len, int las) {
	if (len == n) {
		int res = 0;
		rep(i, q) if (v[b[i]] - v[a[i]] == c[i]) res += d[i];
		ans = max(ans, res);
	} else {
		for (int i = las; i <= m; i++) {
			vector<int> nv = v;
			nv.push_back(i);
			DFS(nv, len + 1, i);
		}
	}
}
int main() {
	scanf("%d%d%d", &n, &m, &q);
	rep(i, q) {
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
		a[i]--, b[i]--;
	}
	vector<int> v;
	DFS(v, 0, 1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3768
// in the name of Allah
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second

typedef long long ll ;

const ll maxn = 2e5 + 10 ;

ll n , dp1[maxn] , dp2[maxn] , mod = 1e9 + 7 ;
vector<ll> g[maxn] ;

void dfs(ll v , ll p)
{

   bool leaf = true ;
   ll ans1=1 , ans2=1 ;

   for(auto u : g[v]){
    if(u != p){
        leaf = false ;
        dfs(u , v) ;
        ans1 = (ans1*((dp1[u]+dp2[u])%mod))%mod ;
        ans2 = (ans2 * (dp1[u]%mod))%mod ;
    }
   }

   if(leaf){
    dp1[v] = 1 ;
    dp2[v] = 1 ;
    return ;
   }

   //cout << ans1 << " " << ans2 << " " << v << endl ;
   dp1[v] = ans1%mod ;
   dp2[v] = ans2%mod ;
}

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

cin >> n ;
for(int i = 1 ; i < n ;i ++){
    int v , u ;
    cin >> v >> u ;
    g[v].push_back(u) ;
    g[u].push_back(v) ;
}

dfs(1 , 0) ;

//cout << dp1[1] << " " << dp2[1] << endl ;

cout << (dp1[1]+dp2[1])%mod ;

    return 0;
}


Measured memory_bytes: 17280
#include <stdio.h>

int main(void){
    int n,k;
    scanf("%d %d",&n,&k);
    int i;
    int num = 1;
    for(i=1;1;i++){
        num *= k;
        if(num > n){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
# coding: utf-8
# Your code here!

N = int(input())
l = [int(input()) for i in range(N)]
l = sorted(l)
sum = 0
for i in range(len(l)):
    if i==N-1:
        sum = sum+(l[i]/2)
    else:
        sum = sum+l[i]
        
        
print(int(sum))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl


signed main(void){
    int W,H;
    int p[114514],q[114514];
    vector<pair<int,int>> P;
    cin >> W >> H;
    REP(i,W){
        cin >> p[i];
        P.push_back({p[i],0});
    }
    REP(i,H){
        cin >> q[i];
        P.push_back({q[i],1});
    }
    int Ans=0;
    sort(P.begin(),P.end());
    
    int inter[214514]={};
    REP(i,P.size()){
        if(i==0){inter[0]=1;continue;}
        if(P[i].second==P[i-1].second){
            inter[i]=inter[i-1]+1;
        }else{
            inter[i]=1;
        }
    }
    //REP(i,P.size()){cout << inter[i] << " ";}cout << endl;
    
    int w=W+1,h=H+1;
    REP(i,P.size()){
        if(i==0){
            if(P[i].second==0){
                Ans+=P[i].first * h;
                //cout << "x " <<P[i].first MM h << endl;
            }else{
                Ans+=P[i].first * w;
                //cout << "y " <<P[i].first MM w << endl;
            }
            continue;
        }
        
        if(P[i].second==0){
            if(inter[i]==1){
                h-=inter[i-1];
            }
            Ans+=P[i].first * h;
            //cout << "x " <<P[i].first MM h << endl;
        }else{
            if(inter[i]==1){
                w-=inter[i-1];
            }
            Ans+=P[i].first * w;
            //cout << "y " <<P[i].first MM w << endl;
        }
        
    }
    
    cout << Ans << endl;
    
    return 0;
}



Measured memory_bytes: 8816
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <queue>

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> ab;
    int a, b;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        ab.push_back(make_pair(a, b));
    } 

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

    int ans = 0;
    priority_queue<int> q;
    int index = 0;
    for(int i = 1; i <= M; i++){
        while(index != N){
            auto temp = ab[index];
            if(temp.first == i){
                q.push(temp.second);
                index++;
            }
            else{
                break;
            }
        }
        
        if(!q.empty()){
            int best = q.top();
            q.pop();

            ans += best;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1908
def binary_search(sorted_list, a):
    left = 0
    right = len(sorted_list)
    while left < right:
        mid = (left + right) // 2
        if sorted_list[mid] < a:
            left = mid + 1
        else:
            right = mid
    return left


def lis(A):
    sorted_list = [10000000000]
    for a in A:
        if sorted_list[-1] < a:
            sorted_list.append(a)
        else:
            sorted_list[binary_search(sorted_list, a)] = a
    return len(sorted_list)
        

if __name__ == "__main__":
    n = int(input())
    a = [int(input()) for i in range(n)]

    print(lis(a))


Measured memory_bytes: 10332
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define vint vector<int>


int main(){
    int a,b;
    while(~scanf("%d%d",&a,&b)) cout << a+b << endl;

    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef DEBBY
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b); i++)
#define sz(v)  (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
#define fs first
#define sd second
#define pb push_back


void solve(){
    unordered_set<string> dic;
    int n ; cin >> n;
    rep(i,1,n){
      string s; cin >> s;
      dic.insert(s);
    }
    cout << dic.size();
} 

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





Measured memory_bytes: 17736
//Multiplication
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{

    long A,B;
    cin >> A >> B;
    cout << (long long)A * B << endl;
    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
using namespace std;
#include <math.h>

int main()
{
	double x1, y1, x2, y2, x3, y3, x, y;
	double ax, ay, bx, by;
	double z1, z2, z3; // ベクトルAとベクトルBの外積のz成分
	
	while (cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x >> y) {
		ax = x2 - x1;
		ay = y2 - y1;
		bx = x - x1;
		by = y - y1;
		z1 = ax * by - ay * bx;
		
		ax = x3 - x2;
		ay = y3 - y2;
		bx = x - x2;
		by = y - y2;
		z2 = ax * by - ay * bx;
		
		ax = x1 - x3;
		ay = y1 - y3;
		bx = x - x3;
		by = y - y3;
		z3 = ax * by - ay * bx;
		
		if ( ( (z1 > 0) && (z2 > 0) && (z3 > 0) ) || ( (z1 < 0) && (z2 < 0) && (z3 < 0) ) )
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a);
        a = (a*a);
        b >>= 1;
    }
    return prod;
}

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

    ll cnt = 0;
    ll sum = 0;
    ll num = 1;
    for(ll i = 0 ; i < 60 ; i++)
    {
        map<ll,ll> m1;
        for(ll j = 0 ; j < n ; j++){
            if(a[j] & (power(2ll , i)))m1[1]++;
            else m1[0]++;
        }

        // debug(i);
        // cout << m1[0] << " " << m1[1] << endl;
        ll prod = m1[0] * m1[1];
        prod += cnt;
        cnt = prod / 2;
        // debug(prod);
        if(prod%2 == 1)sum = (sum%mod + num%mod)%mod;
        num = (num * 2)%mod;
    }
    while(cnt != 0){
        if(cnt%2 == 1){
            sum = (sum%mod + num%mod)%mod;
        }
        cnt /= 2; 
        num = (num * 2)%mod;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
ll D, A;
vector<ll> X, H;

ll solve()
{
    vector<int> ids(N);
    for (int i = 0; i < N; i++)
    {
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
        return X[i] < X[j];
    });
    vector<ll> nX(N), nH(N);
    for (int i = 0; i < N; i++)
    {
        nX[i] = X[ids[i]], nH[i] = H[ids[i]];
    }
    X = nX;
    H = nH;

    vector<ll> S(N + 1, 0);
    ll res = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] < H[i])
        {
            ll need = (H[i] - S[i] + A - 1) / A;

            ll right = X[i] + D * 2;
            int id = upper_bound(X.begin(), X.end(), right) - X.begin();

            S[i] += need * A;
            S[id] -= need * A;
            res += need;
        }
        S[i + 1] += S[i];
    }
    return res;
}

int main()
{
    cin >> N >> D >> A;
    X.resize(N);
    H.resize(N);
    rep(i, 0, N)
    {
        cin >> X[i] >> H[i];
    }
    cout << solve() << endl;
}


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

int main(){
    int k, s;
    cin >> k >> s;
    int count =0;
    // xとyを0〜kまで探索し、zが適正な値になるならcountを増やす
    for( int x = 0; x <= k; x++){
        for ( int y = 0; y <= k; y++){
            int z = s - x - y;
            if (z>= 0 && z <= k){
                count++;
            }
        }
    }
    cout << count << endl;
    
}

Measured memory_bytes: 256
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include<unordered_map>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
#define y1 ezkatka

const long long MXN = 1e6 + 2;
const long long MNN = 2e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int a, b;

int main(){
	ios;
	//freopen("input.txt", "r", stdin);
	cin >> a >> b;
	cout << a * b - (a + b - 1);
	return 0;
}


Measured memory_bytes: 256
s = [
    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
]
print(s[int(input()) - 1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 100005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
 
const int inf = 1e9;
 
int n,m,g[705][705],col[705],vis[705],num[705][705],bk,f[705][705];
 
void dfs(int x, int wtf){
	vis[x] = 1;
	col[x] = wtf;
	++num[col[x]][bk];
	for(int i=1;i<=n;i++)
		if(i!=x && !g[x][i]){
			if(!vis[i]) dfs(i,wtf^1);
			else if(col[i] == col[x]){ puts("-1"); exit(0); }
		}
}

int c(int x,int y){return (((x*(x-1))/2) + ((y*(y-1))/2));}

int main(){
	nfs_mw;
	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x][y] = g[y][x] = 1;
	}
	
	for(int i=1;i<=n;i++)
		if(!vis[i]) ++bk, dfs(i,0);
	
	f[0][0] = 1;
	for(int i=0;i<bk;i++) for(int j=0;j<=n;j++)
		f[i+1][j+num[0][i+1]] |= f[i][j],
		f[i+1][j+num[1][i+1]] |= f[i][j];
	
	int ans = 700*700*700;
	for(int i=n; i>=0; i--) if(f[bk][i]) ans = min(ans,c(i,n-i));
	printf("%d\n",ans);
 
	return 0;
}

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

int main(){
	int A[110],n,a;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>A[i];
	}
	for(int i=0;i<n;i++){
		cout<<A[i];
		if(i!=n-1)cout<<" ";
	}
	cout<<endl;
	for(int i=1;i<n;i++){
		for(int j=i;j>=1;j--){
			if(A[j]<A[j-1]){
				a=A[j];
				A[j]=A[j-1];
				A[j-1]=a;
			}
		}
		for(int j=0;j<n;j++){
			cout<<A[j];
			if(j!=n-1)cout<<" ";
		}
		cout<<endl;
		if(i==n-1)break;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <iomanip>

using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int H, W;
vector<string> C;
int x1, x2;

int cost[310][310];     
int dp[310][310];

int calc_cost(int a, int b)
{
    if (a == H || b == H) return 0;
    if (cost[a][b] >= 0) return cost[a][b];

    int same = (C[H-a-1][x1] == C[H-b-1][x2]);
    int ret = same + calc_cost(a+1, b+1);
    return cost[a][b] = ret;
}

int solve(int a, int b)
{
    if (a == H || b == H) return 0;
    if (dp[a][b] >= 0) return dp[a][b];

    int now_cost = calc_cost(a, b);
    int ret = INF;
    ret = min(ret, now_cost + solve(a+1, b));
    ret = min(ret, now_cost + solve(a, b+1));

    return dp[a][b] = ret;
}

int main()
{
    cin >> H >> W;
    C.resize(H);
    rep(i, H) cin >> C[i];

    int ans = 0;
    for (int i=0; i<W-1; i++) {
        memset(cost, -1, sizeof(cost));
        memset(dp, -1, sizeof(dp));

        x1 = i, x2 = i+1;
        int tmp = solve(0, 0);
        ans += tmp;

#if 0
        rep(y, H) {
            rep(x, H) cerr << cost[x][y] << " ";
            cerr << endl;
        }
        cerr << endl;
#endif
    }

    cout << ans << endl;
}



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

typedef long long LL;
typedef pair<int, int> II;

const int N = (int) 2e5 + 10;
int n, a[N], L[N], R[N];

int main() {
    #ifdef LOCAL
        freopen("Data.inp", "r", stdin);
        freopen("Data.out", "w", stdout);
    #endif

    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);

    for (int i = 1; i <= n; ++i) {
        L[i] = i;
        while (L[i] > 1 && a[L[i] - 1] > a[i]) L[i] = L[L[i] - 1];
    }
    for (int i = n; i >= 1; --i) {
        R[i] = i;
        while (R[i] < n && a[R[i] + 1] > a[i]) R[i] = R[R[i] + 1];
    }

    LL ans = 0;
    for (int i = 1; i <= n; ++i) ans += (LL) a[i] * (R[i] - i + 1ll) *  (i - L[i] + 1ll);
    cout << ans;
    return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<iomanip>
#include<vector>

struct nn{
    int next,weight;
};

struct node{

    std::vector<nn> nex;

};

int n,w[100000],v[100000],u[100000],res[100000];

node no[100000];

int func(int pre,int z,int ww){

    if(ww==0)res[z]=res[pre];
    if(ww==1)res[z]=(res[pre]+1)%2;

    for(auto&& x:no[z].nex){
        if(pre!=x.next)func(z,x.next,x.weight);
    }

    return 0;

}

int main(){

    std::cin>>n;

    for(int i=0;i<n-1;i++){
        std::cin>>u[i]>>v[i]>>w[i];
    }

    for(int i=0;i<n-1;i++){
        no[u[i]-1].nex.push_back((nn){v[i]-1,w[i]%2});
        no[v[i]-1].nex.push_back((nn){u[i]-1,w[i]%2});
    }

    func(0,0,0);

    for(int i=0;i<n;i++)
    std::cout<<res[i]<<std::endl;

    return 0;

}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    ll N; cin >> N;
    if(N==1){
        cout << 0 << endl;
        return 0;
    }

    ll a = 1;
    ll b = 1;
    ll c = 1;
    rep(i, N){
        a = (a*10)%mod;
        b = (b*9)%mod;
        c = (c*8)%mod;
    }
    ll ans = ((a-2*b%mod)%mod + c)%mod;
    while(ans<0) ans += mod; 
    cout << ans << endl;
}

Measured memory_bytes: 3548
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define prr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cout << *it << " = " << a << endl;
	err(++it, args...);
}

#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define pri(a) cout << a << endl;
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(a) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e4 + 1;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, k);
	int cnt = 0, c = 1;
	while (c <= n) cnt++, c *= k;
	cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	if(n%2!=0){
		cout << "No" << endl;
			return 0;
	}
	int k=s.size();
	for(int i=0,j=k/2;j<k;i++,j++){
		if(s[i]!=s[j]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl; 
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    ll n; cin>>n;
    for(ll i=1; i*i<=100*n; i++){
        if((i+1)*i/2>=n){
            cout<<i<<endl;
            return 0;

        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
typedef long long ll;
const int MOD = 1000000007;
 
int main(){
    int m; cin>>m;
    ll d[m],c[m];
    rep(i,m) cin>>d[i]>>c[i];
    ll S=0;
    ll res=0;

    rep(i,m){
         res+=c[i];
         S+=(d[i]*c[i]);
    }
    res--;
    res+=(S-1)/9;

    cout<<res<<endl;
   
}

Measured memory_bytes: 3328
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll frac[100005];

ll mypow(ll a, ll b) {
  ll ans = frac[a];
  ll tmp1, tmp2;
  ll two;
  ll h=mod-2;
  while(h>0) {
    two = 1;
    tmp1 = frac[b];
    tmp2 = frac[a-b];
    while(2*two<h) {
      two *= 2;
      tmp1 *= tmp1;
      tmp1 %= mod;
      tmp2 *= tmp2;
      tmp2 %= mod;
    }
    h -= two;
    ans *= tmp1*tmp2%mod;
    ans %= mod;
  }
  return ans;
}

int main() {
  frac[0] = 1;
  for(ll i=1;i<100005;++i) frac[i] = frac[i-1]*i%mod;
  int N, K;
  cin>>N>>K;
  vector<ll> A(N);
  for(int i=0;i<N;++i) {
    cin>>A[i];
  }
  sort(A.begin(), A.end());
  ll ans = 0;
  ll index;
  for(int i=0;i<N;++i) {
    if(i>=K-1) {
      ans += A[i]*mypow(i, K-1)%mod;
      ans %= mod;
    }
  }
  int num;
  for(int i=0;i<N;++i) {
    num = N-i-1;
    if(num>=K-1) {
      ans = (ans-A[i]*mypow(num, K-1)%mod+mod)%mod;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long ma(long a,long b){
  long r1=0,r2=0,ret;
  while(a){
    a/=10;
    r1++;
  }
  while(b){
    b/=10;
    r2++;
  }
  ret = (r1>r2?r1:r2);
  return ret;
}
int main(){
  long n,c,ans=13;
  cin>>n;
  map<long,long> pair;
  for(long i=1;i*i<=n;i++){
    if(n%i==0){
      pair.insert(make_pair(i,n/i));
    }
  }
  for(auto it=pair.begin();it!=pair.end();it++){
    c=ma((*it).first,(*it).second);
    ans=(ans<c?ans:c);
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first 
#define s second 
using namespace std;
pair<int,int> p[100005];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i].f;p[i].s=i;
	}
	sort(p+1,p+n+1);
	for(int i=1;i<=n;i++)cout<<p[i].s<<' ';
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
			int n;
			while (0 != (n = Integer.parseInt(in.readLine()))) {
				int[] a = new int[n];
				for (int i = 0; i < n; i++) {
					a[i] = Integer.parseInt(in.readLine());
				}
				Arrays.sort(a);
				long time = 0;
				long sum = 0;
				for (int i = 0; i < n; i++) {
					time += sum;
					sum += a[i];
				}
				System.out.println(time);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 11000
#include<stack>
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int MAXN=400005;
int N,A[MAXN],P;
int vis[MAXN];
int V[MAXN],R[MAXN];
long long K,Ans,Sum;
void Print(int p){
	for(int i=p;i<=N;i++){
		if(R[i]<=N)i=R[i];
		else printf("%d ",A[i]);
	}puts("");
}
void Solve(){
	//Ans++;
	if(K==0)return ;
	if(K==1){Print(P);return ;}
	if(R[P]>=N){K--;
		if(R[P]==2*N)K--;
		P=(R[P]-N)%N+1;
	}
	else P=R[P]+1;
	Solve();
}
int main(){
	//freopen("dnd.in","r",stdin);
	//freopen("dnd.out","w",stdout);
	scanf("%d%lld",&N,&K);
	for(int i=1;i<=N;i++)
		scanf("%d",&A[i]);
	for(int i=2*N;i>=N+1;i--)V[A[i-N]]=i;
	for(int i=N;i>=1;i--)R[i]=V[A[i]],V[A[i]]=i;
	int p=1;
	while(!vis[p]){
		vis[p]=1;Sum+=R[p]-p;
		if(R[p]>N)p=(R[p]-N)%N+1;
		else p=R[p]%N+1;
	}Sum=Sum/N+1;K%=Sum;
	P=p;Solve();
	//printf("%lld\n",Ans);
}



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

using namespace std;
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* [💭] [💡] [🎈] */

const ld pi = 3.1415926535897932384626433;

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

    ld a, b, h, m;
    cin >> a >> b >> h >> m;

    ld t1 = (60 * h + m) / (12 * 60) * 2 * pi;
    ld t2 = (m) / 60 * 2 * pi;

    ld x1 = a * cos(t1), y1 = a * sin(t1);
    ld x2 = b * cos(t2), y2 = b * sin(t2);
    cout << fixed << setprecision(15) << hypotl(x1 - x2, y1 - y2);

    return 0;
}

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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << "\n";

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

  double N;
  CIN(N);

  double count = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 2 == 1)
      count++;
  }
  double a = count / N;
  PS(a);
  return 0;
}


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

int main()
{   
    int S, W;
    cin >> S >> W;
    if(S<=W){
        std::cout << "unsafe" << std::endl;
    }else{
        std::cout << "safe" << std::endl;
    }
    return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

ll dp[101][100001];

ll v[101], w[101];

int n;

ll solve(int idx, int sisaW){
	if(idx == n){return 0;}
	if(dp[idx][sisaW] != -1){return dp[idx][sisaW];}
	if(sisaW < w[idx]){return solve(idx+1, sisaW);}
	return dp[idx][sisaW] = max(solve(idx+1, sisaW), v[idx] + solve(idx+1, sisaW - w[idx]));
}

int main(){
	int W,i,j;
	scanf("%d %d",&n,&W);
	for(i=0;i<n;i++){
		scanf("%lld %lld",&w[i],&v[i]);
	}
	memset(dp, -1, sizeof dp);
	printf("%lld\n",solve(0, W));
	return 0;
};

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define EB emplace_back

typedef std::pair <int, int> pr;
typedef std::vector <pr> vecpr;
const int N = 108, N2 = 10054;

int R, C;
int A1[N2], A2[N2], ans1[N][N], ans2[N][N];
int matL[N], matR[N];
bool used[N];
vecpr G[N];

bool dfs(int x) {
	int y;
	for (const pr &p : G[x])
		if (!used[y = p.first])
			if (used[y] = true, !~matL[y] || dfs(matL[y]))
				return matL[y] = x, matR[x] = y, true;
	return false;
}

int main() {
	int i, j, x, n, match;
	scanf("%d%d", &R, &C);
	for (i = 0; i < R; ++i) {
		for (j = 0; j < C; ++j) scanf("%d", &x), A1[--x] = i;
		std::fill(A2 + i * C, A2 + (i + 1) * C, i);
	}
	for (i = 0; i < R * C; ++i) G[ A1[i] ].EB(A2[i], i + 1);
	for (match = 0; match < C; ++match) {
		memset(matL, -1, R << 2), memset(matR, -1, R << 2);
		for (i = 0; i < R; ++i) memset(used, false, R), assert( dfs(i) );
		for (i = 0; i < R; ++i)
			for (n = G[i].size(), j = 0; j < n; ++j)
				if (G[i][j].first == matR[i]) {
					ans1[i][match] = ans2[ matR[i] ][match] = G[i][j].second;
					G[i].erase(G[i].begin() + j); break;
				}
	}
	for (i = 0; i < R; ++i) for (j = 0; j < C; ++j) printf("%d%c", ans1[i][j], j == C - 1 ? 10 : 32);
	for (i = 0; i < R; ++i) for (j = 0; j < C; ++j) printf("%d%c", ans2[i][j], j == C - 1 ? 10 : 32);
	return 0;
}

Measured memory_bytes: 640
#include <string>
#include <iostream>

int main(int argc, char** argv) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	
	std::string a, b, str;
	int n, m;
	std::cin >> a >> b >> n >> m >> str;
	std::cout << (n - (str == a)) << " " << (m - (str == b)) << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
#define N 50
#define X 50
 
int main() {
	static long long int abc[N+1][N*X+1];
	int n,m,h,i,j;
	long long int cnt;
 
	scanf("%d%d",&n,&m);
	abc[0][0] = 1;
	for (h=1;h<=n;h++) {
		int x;
		scanf("%d", &x);
		for (i=h;i>0;i--)
			for (j=x;j<=i*X;j++) abc[i][j] += abc[i-1][j-x];
	}
	cnt=0;
	for (i=1;i<=n;i++)
		cnt+=abc[i][i*m];
	printf("%lld\n", cnt);
	return 0;
}

Measured memory_bytes: 768
from bisect import bisect_right
n=int(input())
s=input()
ind=[[] for i in range(10)]
i=0
for c in s:
    ind[ord(c)-48].append(i)
    i+=1
cnt=0
for i in range(1000):
    j=i//100
    k=i//10-j*10
    l=i%10
    if len(ind[j])*len(ind[k])*len(ind[l])==0:
        continue
    if ind[j][0]<ind[k][-1]:
        if ind[k][bisect_right(ind[k],ind[j][0])]<ind[l][-1]:
            cnt+=1
print(cnt)

Measured memory_bytes: 39792