akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define NL '\n'
#define C char
#define D double
#define F float
#define S string

#define sz(x) x.size()
#define INF LONG_MAX
#define IINF LLONG_MAX
#define PI (2.0*acos(0.0))

#define sfi(x) scanf("%d",&x)
#define sfi2(x,y) scanf("%d %d",&x,&y)
#define sfi3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sfl(x) scanf("%lld",&x)
#define sfl2(x,y) scanf("%lld %lld",&x,&y)
#define sfl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sfd(x) scanf("%lf",&x);

#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max(max3(a,b,c),d)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min(a,min3(b,c,d))

#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define For(i, j, k) for(int i = j; i <= k; i++)
#define Rof(i, j, k) for(int i = j; i >= k; i--)
#define all(x) x.begin(),x.end()
#define asort(x) sort(all(x));
#define dsort(x) sort(all(x), greater<int>())
#define unq(x) x.erase(unique(x.begin(),x.end()),x.end())

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define READ freopen("input.txt","r",stdin)
#define WRITE freopen("output.txt","w",stdout)
#define IOS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;

LL gcd(LL a,LL b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
LL lcm(LL a,LL b)
{
    return a/gcd(a,b)*b;
}

LL bigmod(LL base, LL power, LL mod)
{
    if(power==0) return 1;
    else if(power%2==1)
    {
        LL value1 = base % mod; LL value2 = (bigmod(base,power-1,mod))%mod;
        return (value1*value2)%mod;
    }
    else
    {
        LL value1 = (bigmod(base,power/2,mod))%mod;
        return (value1*value1)%mod;
    }
}

int main()
{
    //A
    /*int n;
    sfi(n);
    int a,b;
    sfi2(a,b);
    int aa = a;
    if(n==1) printf("OK");
    else
    {
        int divi = a / n;
        a = n * divi;

        while(true)
        {
            if(a%n==0 and a>=aa and a<=b)
            {
                cout<<"OK";
                break;
            }
            if(a>b)
            {
                cout<<"NG";
                break;
            }
            a = a + n;
        }
    }*/



    //B
    /*LL n;
    sfl(n);

    LL pre = 100;

    int count = 0;
    while(true)
    {
        if(pre>=n)
        {
            cout<<count;
            break;
        }
         pre = pre + (pre/100);
         count++;
    }*/


    //D

    LL a,b,n;
    sfl3(a,b,n);

    if(n>=b)
    {
        LL bb = b-1;
        LL ans = ((a*bb)/b) - (a*(bb/b));
        cout<<ans;
    }
    else
    {
        LL ans = ((a*n)/b) - (a*(n/b));
        cout<<ans;
    }
}


Measured memory_bytes: 3760
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	int mod = 1000000007;

	static public int diff(int[] a, int i, int j) {
		return Math.abs(a[i] - a[j]);
	}

	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		out = new PrintWriter(new BufferedOutputStream(System.out));
		int n = sc.nextInt();
		int amount = sc.nextInt();

		long[] w = new long[n];
		long[] v = new long[n];

		for (int i = 0; i < n; i++) {
			w[i] = sc.nextLong();
			v[i] = sc.nextLong();
		}

		long[][] dp = new long[n + 1][amount + 1];

		for (int i = 1; i <= n; i++) {
			long _w = w[i - 1];
			long _v = v[i - 1];
			for (int j = 1; j <= amount; j++) {
				dp[i][j] = dp[i - 1][j];
				if (j - _w >= 0) {
					dp[i][j] = Math.max(dp[i][j], dp[i - 1][j - (int)_w] + _v);
				}
			}
		}

		out.print(dp[n][amount]);
		/*
		 * int n = sc.nextInt(); // read input as integer long k = sc.nextLong(); //
		 * read input as long double d = sc.nextDouble(); // read input as double String
		 * str = sc.next(); // read input as String String s = sc.nextLine(); // read
		 * whole line as String
		 * 
		 * int result = 3*n; out.println(result); // print via PrintWriter
		 */

		// Stop writing your solution here. -------------------------------------
		out.close();
	}

	// -----------PrintWriter for faster output---------------------------------
	public static PrintWriter out;

	// -----------MyScanner class for faster input----------
	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

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

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	// --------------------------------------------------------
}


Measured memory_bytes: 138360
x,n = map(int, input().split())
p =list(map(int, input().split()))
m = 10**10
ans = 10**10
if n == 0:
    print(x)
    exit()
for i in range(1000):
    if i in p:
        continue
    if m > abs(i-x):
        m = abs(i-x)
        ans = i
    elif m==abs(i-x):
        ans = min(ans,i)
print(ans)


Measured memory_bytes: 9196
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
while(x->left !=NIL) x=x->left;
return x;
}

Node treeMaximum(Node x){
while(x->right != NIL) x=x->right;
return x;
}

Node treeSuccessor(Node x){
	Node y;
if(x->right != NIL) return treeMinimum(x->right);

y=x->parent;
while(y!=NIL && x==y->right){
	x=y;
	y=y->parent;
}
return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
if(z->left==NIL || z->right==NIL) y=z;
else y=treeSuccessor(z);
if(y->left !=NIL) x=y->left;
else x=y->right;
if(x!=NIL) x->parent=y->parent;
if(y->parent ==NIL)
root=x;
else if(y==y->parent->left) y->parent->left=x;
else y->parent->right=x;
if(y!=z) z->key=y->key;
}

Node treeSearch(Node u, int k){
	while(u!=NIL&&k!=u->key){
		if(k<u->key) u=u->left;
		else u=u->right;
	}
	 return u;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent = y;

  if(y==NIL) root=z;
  else if(z->key<y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
if(u!=NIL){
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }
  }

  return 0;
}


Measured memory_bytes: 20460
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "random"
#include        "chrono"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          pb push_back
#define          N (int)2e5+5
#define          PI acos(-1.0)
#define          int long long 
#define          vi vector<int>
#define          mod 1000000007
#define          ld long double
#define          eb emplace_back
#define          mii map<int,int>
#define          vpii vector<pii>
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) x.rbegin(),x.rend()
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	set<int>  a{ 2 , 4, 5, 7, 9};
	set<int>  b{ 0 , 1, 6 , 8};

	cin >> n;

	int d = n%10;

	if( a.count(d) )
	{
		cout << "hon\n";
	}
	else if( b.count(d) )
	{
		cout << "pon\n";
	}
	else
	{
		cout << "bon\n";
	}

}

int32_t main()
{
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}


Measured memory_bytes: 8316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    string s;
    int Q,q,f,r=0;
    char c;
    cin>>s>>Q;
    for(int i=0;i<Q;i++){
        cin>>q;
        if(q==1){
            r++;
        }
        else{
            cin>>f>>c;
            if((r%2==0&&f==1)||(r%2==1&&f==2)){
                s.insert(s.begin(),c);
            }
            else{
                s+=c;
            }
        }
    }
    if(r%2==1) reverse(s.begin(),s.end());
    cout<<s;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
int a[100010], b[100010];
int main() {
	int n, h;
	cin >> n >> h;
	rep(i,n) cin >> a[i] >> b[i];
	//sort(a,a+n,greater<int>());
	sort(b,b+n,greater<int>());
	
	int ma = *max_element(a,a+n);
	int k = -1;
	rep(i,n) {
		if (b[i] <= ma) {
			k = i;
			break;
		}
	}

	int ans = 0;
	if (k == -1) {
		rep(i,n) {
			h -= b[i];
			ans++;
			if (h <= 0) {
				cout << ans << endl;
				return 0;
			}
		}
		ans += (h+ma-1) / ma;
	}
	else {
		rep(i,k) {
			h -= b[i];
			ans++;
			if (h <= 0) {
				cout << ans << endl;
				return 0;
			}
		}
		ans += (h+ma-1) / ma;
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4416
import Text.Printf

main = do
  [a,b,k] <- map read . words <$> getLine :: IO [Int]
  let (x,y) = takahashi a b k
  printf "%d %d\n" x y
  
takahashi a b k
  | k==0 = (a,b)
  | otherwise = aoki (a`div`2) (b+a`div`2) (k-1)

aoki a b k
  | k==0 = (a,b)
  | otherwise = takahashi (a+b`div`2) (b`div`2) (k-1)



Measured memory_bytes: 508
//abc098_c.cpp
//Sat May 26 20:47:07 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;

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

	int count = 0;

	for (int i=1;i<n;i++){
		if (s[i] == 'E'){
			count++;
		}
	}

	int min = count;

	for (int i=1;i<n;i++){
		if (s[i-1] == 'E' && s[i] == 'E'){
			count--;
		}else if (s[i-1] == 'W' && s[i] == 'W'){
			count++;
		}
		if (min > count){
			min = count;
		}
	}

	cout << min << endl;
}

Measured memory_bytes: 900
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int lowerBound = 0;
      int upperBound = 0;
      if(s.length() % 2 == 0) { 
        upperBound = s.length() / 2;
        lowerBound = upperBound - 1;
      } else {
        upperBound = s.length()/2 + 1;
        lowerBound = s.length()/2 - 1;
      }
      int k = (s.length() + 1) / 2;
      while(upperBound < s.length() && lowerBound >= 0 && s.charAt(upperBound) == s.charAt(upperBound - 1) && s.charAt(lowerBound) == s.charAt(lowerBound + 1)) {
          upperBound++;
          lowerBound--;
          k++;
      }

      System.out.println(k);
  }
}

Measured memory_bytes: 25172
#import <stdio.h>

int main(){
    char a[20] = {'\0'};
    int N=0;
    char c = getchar();
    while(c>='0' && c<='9'){
        a[N]=c;
        N++;
        c = getchar();
    }
    for(int i=0;i<N;i++){
        if (a[i] == '9') {
            continue;
        } else if (a[i] == '0' || i>0) {
            a[i-1]--;
            for (int j=i;j<N;j++){
                a[j] = '9';
            }
        } else if (i<N-1) {
            int nineOnly = 1;
            for(int j=i+1;j<N;j++){
                if(a[j] !=
                   '9'){
                    nineOnly = 0;
                    a[j] = '9';
                }
            }
            if(!nineOnly){
                a[i]--;
            }
        } else if (N>1) {
            a[i] = '9';
            a[i-1]--;
        }
    }
    int sum = 0;
    for(int i=0;i<N;i++){
        sum += a[i] - '0';
    }
    printf("%d", sum);
}


Measured memory_bytes: 7116
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        map<string, int> mp;
        int m = 0;

        REP(i, n) {
                string s;
                cin >> s;

                mp[s]++;

                m = max(m, mp[s]);
        }

        for (auto it : mp) {
                if (it.second == m) {
                        cout << it.first << endl;
                }
        }

        return 0;
}


Measured memory_bytes: 25216
N,M,L,Q;
D[301][301];
i,j,k;
a,b,c;
main()
{
	scanf("%d%d%d",&N,&M,&L);
	for(i=1;i<=N;i++)for(j=0;j<=N;j++)D[i][j]=1000000001;
	for(i=0;i<M;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		D[a][b]=D[b][a]=c;
	}
	for(k=1;k<=N;k++)for(i=1;i<=N;i++)for(j=1;j<=N;j++)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	for(i=1;i<=N;i++)for(j=1;j<=N;j++)
	{
		D[i][j]=D[i][j]>L?1000000000:1;
	}
	for(k=1;k<=N;k++)for(i=1;i<=N;i++)for(j=1;j<=N;j++)
		if(D[i][j]>D[i][k]+D[k][j])D[i][j]=D[i][k]+D[k][j];
	scanf("%d",&Q);
	for(i=0;i<Q;i++)
	{
		scanf("%d%d",&a,&b);
		printf("%d\n",D[a][b]<1000000000?D[a][b]-1:-1);
	}
}

Measured memory_bytes: 768
import std.stdio,
       std.string,
       std.conv,
       std.algorithm,
       std.array;

void main() {
    while(1) {
        auto x = readln.split.map!(x=>x.to!int).array;
        if(x == [0, 0, 0, 0])
            return;

        bool f = false;
loop:    foreach(i; 0 .. 4) {
            foreach(j; 0 .. 4) {
                if(j == i)
                    continue;
                foreach(k; 0 .. 4) {
                    if(k == i || k == j)
                        continue;
                    foreach(l; 0 .. 4) {
                        if(l == i || l == j || l == k)
                            continue;
                        auto a = [x[i], x[j], x[k], x[l]];
                        f = a.solve;
                        if(f)
                            break loop;
                    }
                }
            }
        }
        if(!f)
            0.writeln;
    }
}

bool solve(int[] a) {
    immutable ops = ['+', '-', '*'];
    foreach(x; ops) {
    foreach(y; ops) {
    foreach(z; ops) {
        char[] op = [x, y, z];
        if(calc1(a, op) == 10) {
                writefln("((%d %c %d) %c %d) %c %d", a[0], op[0], a[1], op[1], a[2], op[2], a[3]);
                return true;
        } else if(calc2(a, op) == 10) {
                writefln("(%d %c %d) %c (%d %c %d)", a[0], op[0], a[1], op[1], a[2], op[2], a[3]);
                return true;
        }
    }}}
    return false;
}

int calc1(int[] a, char[] op) {
    return sub_calc(sub_calc(sub_calc(a[0], op[0], a[1]), op[1], a[2]), op[2], a[3]);
}


int calc2(int[] a, char[] op) {
    return sub_calc(sub_calc(a[0], op[0], a[1]), op[1], sub_calc(a[2], op[2], a[3]));
}

int sub_calc(int a, char op, int b) {
    switch(op) {
        case '+':
            return a + b;
            break;
        case '-':
            return a - b;
            break;
        case '*':
            return a * b;
            break;
        default:
            throw new Exception("error");
            break;
    }
}

Measured memory_bytes: 1084
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<utility>
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define ll long long
using namespace std;
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	string s;
	int k;
	cin >> k >> s;
	if (s.length()<=k) {
		cout << s << endl;
	}
	else {
		for (int i = 0; i < k; i++) {
			cout << s[i];
		}
		cout << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3612
// input! .. https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

use std::cmp::max;
fn main() {
    input! {
        n: usize,
        ta: [(u64, u64); n],
    }
    let (mut t, mut a) = ta[0];
    for i in 1..n {
        let (tt, aa) = ta[i];
        // (t + p):(a + q) = tt:aa
        // t + p < r*aa => r = ceil(a/aa)
        // a + q < s*aa => s = ceil(t/tt)
        let k = max((a + aa - 1) / aa, (t + tt - 1) / tt);
        t = tt * k;
        a = aa * k;
    }
    println!("{}", t + a);
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    for(int i=0; i<n; i++){
        cout<<s[i]<<t[i];
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
    using namespace std ;
    using ll = long long;
    vector<ll> a(3);
    cin >> a[0] >> a[1] >> a[2];
    sort(a.begin(), a.end());
    ll ans = a[2] - a[1];
    ll aaa = (a[2] - (a[0] + ans)) / 2 ;
    cout << ans + aaa + (aaa * 2 + a[0] + ans != a[2] ? 2 : 0) << endl ;
    
}

Measured memory_bytes: 256
#import bisect,collections,copy,heapq,itertools,math,numpy,string
#from operator import itemgetter
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
A,B = LS()
for i,c in enumerate(B):
  if c == '.':
    break
res = str(int(A)*int(B[0:i]+B[i+1:]))
pos = len(res)-(len(B)-i-1)
if pos <= 0:
  print("0")
else:
	print(res[0:pos])

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

using namespace std;

#define For(i, a, b) for (register int i = (a), i##_end = b; i <= i##_end; ++ i) 
#define FOR(i, a, b) for (register int i = (a), i##_end = b; i >= i##_end; -- i) 
#define go(x, i) for (register int i = head[x]; i; i = nxt[i])
#define mem(a, b) memset(a, b, sizeof(a))
#define getc getchar_unlocked
#define putc putchar_unlocked
#define inf (0x3f3f3f3f)
#define INF (2e18)
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define y1 igniubi

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ldb;
typedef double db;
typedef pair<int, int> PII;
typedef pair<ll, int> PLI;

inline void procStatus() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>());
}

const int N = 2e3 + 10;

PII E[N]; int n, k, ans = inf;

int to[N << 1], nxt[N << 1], head[N], e = 1;

inline void add(int x, int y) {
	to[++ e] = y; nxt[e] = head[x]; head[x] = e; 
}

namespace Sub1 {
	int dep[N], res, now[2];

	inline void dfs(int x, int dad, int typ) {
		go(x, i) if(to[i] ^ dad && to[i] ^ now[typ]) {
			dep[to[i]] = dep[x] + 1; 
			dfs(to[i], x, typ);
		}
		if (dep[x] > (k - 1) >> 1) ++ res;
	}

	inline void Solve() {
		For(i, 2, n) {
			mem(dep, res = 0);
			now[0] = E[i].x, now[1] = E[i].y;
			dfs(now[0], 0, 1), dfs(now[1], 0, 0);
			ans = min(ans, res);
		}
	}
}

namespace Sub2 {
	int dep[N], res;

	inline void dfs(int x, int dad) {
		go(x, i) if(to[i] ^ dad) {
			dep[to[i]] = dep[x] + 1; 
			dfs(to[i], x);
		}
		if (dep[x] > k >> 1) ++ res;
	}

	inline void Solve() {
		For(i, 1, n) {
			mem(dep, res = 0), dfs(i, 0);
			ans = min(ans, res);
		}
	}
}

int main() {
	//freopen("AT1981.in", "r", stdin);
	//freopen("AT1981.out", "w", stdout);

	int x, y;

	scanf("%d%d", &n, &k);
	For(i, 2, n) {
		scanf("%d%d", &x, &y);
		add(x, y), add(y, x);
		E[i] = mp(x, y);
	}

	if (k & 1) Sub1::Solve();
	else Sub2::Solve();

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 384
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let r: usize = iter.next().unwrap().parse().unwrap();

    println!("{}", 3 * r * r);
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7
#s=input().rstrip()
    
r=I()
print(2*r*pi)

Measured memory_bytes: 9476
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        mut ab: [(usize, usize); n],
    }
    ab.sort_by_key(|&(_, bi)| bi);
    let mut t = 0;
    for &(ai, bi) in &ab {
        t += ai;
        if t > bi {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 9156
import Data.List
main=do
 getLine
 a<-sort.map(read::String->Int).words<$>getLine
 getLine
 b<-sort.map read.words<$>getLine
 putStrLn$if f a b then"YES"else"NO"
f a[]=True
f []b=False
f(a:as)(b:bs)
 |a==b=f as bs
 |a>b=False
 |a<b=f as(b:bs)

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

int main() {
  int n, k, num, ans = 0;
  cin >> n >> k;
  vector<int> d(n);
  rep(i,n) d[i] = 0;
  rep(i,k){
    cin >> num;
    rep(j,num){
      int a;
      cin >> a;
      d[a - 1]++;
    }
  }
  rep(i,n) if(d[i] == 0) ans++;
  cout << ans << endl;
}

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

const int mod = 2019;
struct mint {
    long long x;
    mint(long long x = 0): x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

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

    int l, r;
    cin >> l >> r;

    int modL = l % 2019;
    int divL = l / 2019;
    int modR = r % 2019;
    int divR = r / 2019;
    if (divL == divR) {
        int mini = 2019;
        for (int i = modL; i < modR; i++) {
            for (int j = modL + 1; j <= modR; j++) {
                int tmp = (i * j) % 2019;
                mini = min(mini, tmp);
            }
        }
        cout << mini << '\n';
    }
    else cout << 0 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

ll n;

string d[N];

int ans[N];
void f(int id, ll a, ll b, ll c)
{
	if(id > n)
	{
		cout << "Yes\n";
		for(int i = 1; i <= n; i ++)
		{
			cout << d[i][ans[i]] << '\n';
		}
		exit(0);
	}
	char x = d[id][0], y = d[id][1];
	swap(x, y);
	ll  A = a, B = b, C = c;
		if(x == 'A')
			a --;
		if(x == 'B')
			b --;
		if(x == 'C')
			c --;
		if(y == 'A')
			a ++;
		if(y == 'B')
			b ++;
		if(y == 'C')
			c ++;
	ans[id] = 0;
	if(a >= 0 && b >= 0 && c >= 0)
		f(id + 1, a, b, c);
	a = A;
	b = B;
	c = C;
	swap(x, y);
		if(x == 'A')
			a --;
		if(x == 'B')
			b --;
		if(x == 'C')
			c --;
		if(y == 'A')
			a ++;
		if(y == 'B')
			b ++;
		if(y == 'C')
			c ++;
	ans[id] = 1;
	if(a >= 0 && b >= 0 && c >= 0)
		f(id + 1, a, b, c);
}

int main()
{
	ll a, b, c;
	cin >> n >> a >> b >> c;
	for(int i = 1; i <= n; i ++)
		cin >> d[i];	
	f(1,a,b,c);




	cout << "No\n";




	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 20348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する

int main(){
    int n,m;
    cin >> n;
    vector<int>  t(n);
    rep(t,n);
    cin >> m;
    vector<int> p(m),x(m);
    for(int i=0;i<m;i++){cin >> p.at(i) >> x.at(i);}
    for(int i=0;i<m;i++){
        int tmp = t.at(p.at(i)-1);
        t.at(p.at(i)-1)=x.at(i);
        ll sum = accumulate(t.begin(), t.end(),0);
        cout << sum << endl;
        t.at(p.at(i)-1) = tmp;
    }
    
}

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

#define deb(x) cout << #x << "=" << x << endl
#define ll long long

const int mod = 1000000007;
const int N = 3e5, M = N;

void solve() {
	ll a, b, n, m;
	ll input;
	string s, t;
	cin >> s >> t;
	n = s.length();
	m = t.length();
	ll dp[n + 1][m + 1];
	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			if (i == 0 || j == 0)
				dp[i][j] = 0;
			else if (s[i - 1] == t[j - 1])
				dp[i][j] = 1 + dp[i - 1][j - 1];
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	// cout << dp[n][m] << endl;
	string str;
	int i = n, j = m;
	while (i > 0 && j > 0)
	{
		if (s[i - 1] == t[j - 1])
		{
			str += s[i - 1];
			i--;
			j--;
		}
		else if (dp[i - 1][j] > dp[i][j - 1])
			i--;
		else
			j--;

	}
	reverse(str.begin(), str.end());
	cout << str << endl;














}



int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}



Measured memory_bytes: 73960
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
#define INF 1000000
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<int, int> P;

struct edge{ int u, v; lli cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
	vector< vector<lli> > distance_matrix;
};


template <typename T>
vector<int> argsort(const vector<T> &v) {

  // initialize original index locations
  vector<int> idx(v.size());
  iota(idx.begin(), idx.end(), 0);

  // sort indexes based on comparing values in v
  sort(idx.begin(), idx.end(),
       [&v](int i1, int i2) {return v[i1] < v[i2];});

  return idx;
}

template<typename T>
void displayVector(vector<T> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}

int count_comb(int a, int b, int c){
  if(a!=b && b!=c){ return 6; }
  else if( a==b && b==c){ return 1; }
  else{ return 3; }
}

string sub(string str, int start, int end){
  // require : start < end
  return str.substr(start, end-start+1);
}

struct C{ int a; int b; };

int main(){
  lli n, k; cin >> n >> k;
  vector<C> vec(n);
  REP(i, n){ cin >> vec[i].a >> vec[i].b; }

  sort(vec.begin(), vec.end(),
       [](C c1, C c2) {return c1.a < c2.a;} );

  lli now=0;
  REP(i,n){
    now += vec[i].b;
    if( k<=now ){
      cout << vec[i].a << endl;
      break; 
    }
  }
  return 0;
}

Measured memory_bytes: 3940
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;




int main(void) {
    ll N;
    cin >> N;
    ll i, j;
    ll l[10];
    ll a, b, c;
    cin >> a >> b >> c;
    for(i=0; i<N; i++) cin >> l[i];
    
    ll ans=INF;
    for(i=0; i<pow(4, N); i++) {
        ll t=i;
        ll ta=0, tb=0, tc=0;
        ll cnt=N;   //a, b, cのいずれかを作るために使われる竹の数
        for(j=0; j<N; j++) {
            if(t%4==0) ta+=l[j];
            else if(t%4==1) tb+=l[j];
            else if(t%4==2) tc+=l[j];
            else cnt--;
            t/=4;
        }
        
        if(ta==0 || tb==0 || tc==0) continue; //それぞれ少なくとも1本は竹が必要なため
        if(cnt<3) continue;
        chmin(ans, abs(ta-a)+abs(tb-b)+abs(tc-c)+10*(cnt-3));//10*(cnt-3):竹を3本にするのにかかるコスト
        
    }
    
    pt(ans);
}




Measured memory_bytes: 256
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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(){
  int N;
  cin >> N;
  vector<vector<int>> F(N,vector<int> (10));
  for(int i=0; i<N; i++){
    for(int j=0; j<10; j++){
      cin >> F[i][j];
    }
  }
  vector<vector<int>> P(N,vector<int> (11));
  for(int i=0; i<N; i++){
    for(int j=0; j<=10; j++){
      cin >> P[i][j];
    }
  }
  int ans = -mod;
  for(int bit=1; bit<(1<<10); bit++){
    int temp=0;
    vector<int> cnt(N,0);
    for(int i=0; i<10; i++){
      if(bit & (1<<i)){
        for(int j=0; j<N; j++){
          if(F[j][i]){
            cnt[j]++;
          }
        }
      }
    }
    for(int i=0; i<N; i++){
      temp += P[i][cnt[i]];
    }
    chmax(ans,temp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
H = list(map(int, input().split()))
M = []
for _ in range(m):
    M.append(list(map(int, input().split())))

cnt = []
for i in range(m):
    if H[M[i][0]-1] < H[M[i][1]-1]:
        cnt.append(M[i][0])
    elif H[M[i][0]-1] > H[M[i][1]-1]:
        cnt.append(M[i][1])
    else:
        cnt.append(M[i][0])
        cnt.append(M[i][1])
        
import collections
c = collections.Counter(cnt)
print(n-len(c))

Measured memory_bytes: 37172
//hinagata.cpp
//作成日
//更新日
//目的
//手段
/*includes*/
#include <bits/stdc++.h>
/*namespace*/
using namespace std;
using ll= long long;
/*define macro*/
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REPi(i,a,b) for(ll i=(a);i<(b);i++)
#define REPRi(i,a,b) for(ll i=(a);i>(b);i--)
#define ALL(x) (x).begin(),(x).end()

int main(){
    int N;
    cin>>N;
    vector<int> P(N);
    vector<int> Q(N);
    REP(i,N){
        cin>>P[i];
    }
    REP(i,N){
        cin>>Q[i];
    }
    vector<int> R(N);
    REP(i,N){
        R[i]=i+1;
    }
    int count=0;
    int a;
    int b;
    do{
        if(P==R){
            a=count;
        }
        if(Q==R){
            b=count;
        }
        count+=1;
    }while(
        next_permutation(ALL(R))
    );
    cout<<abs(a-b)<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC101_B();
        }

        static void ABC101_B()
        {
            var N = int.Parse(Console.ReadLine());
            var tmp = N;
            var S = 0;
            while (tmp > 0)
            {
                S += tmp % 10;
                tmp = tmp / 10;
            }

            Console.WriteLine(N % S == 0 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        for(int i=0;i<str.length();i++){
            char c = str.charAt(i);
            if(c>='a'&&c<='z') System.out.printf("%c",c-32);
            else if(c>='A'&&c<='Z') System.out.printf("%c",c+32);
            else System.out.printf("%c",c);
        }
        System.out.println();
        sc.close();
    }
}


Measured memory_bytes: 29500
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 4000 + 20 , inf = 1e9 + 20 ;
int n , a[N] ;
char c[N] ;

int val[2][N][N] , dp[N][N] ;
bool mark[2][N] ;

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

	cin >> n ;
	for (int i = 0 ; i < 2 * n ; i ++) cin >> c[i] >> a[i] , a[i] -- ;

	for (int i = 0 ; i < 2 * n ; i ++) {
		bool f = (c[i] == 'B') ;

		mark[f][a[i]] = 1 ;

		for (int j = n - 1 ; j >= 0 ; j --) {
			val[f][a[i]][j] = val[f][a[i]][j + 1] + mark[!f][j] ;
		}
	}	

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

			if (!i && !j) dp[i][j] = 0 ;

			if (i) dp[i][j] = min(dp[i][j] , dp[i - 1][j] + val[0][i - 1][j]) ;
			if (j) dp[i][j] = min(dp[i][j] , dp[i][j - 1] + val[1][j - 1][i]) ;
		}
	}

	int ans = dp[n][n] ;

	for (int i = 0 ; i < 2 * n ; i ++)
		for (int j = 0 ; j < i ; j ++)
			if (c[i] == c[j] && a[i] < a[j]) ans ++ ;

	cout << ans << '\n' ;
}


Measured memory_bytes: 100096
#include <cstdio>
long long d[55][5005];
int main() {
	int i, j, n, a, x, z=0;
	scanf("%d%d", &n, &a);
	d[0][2500] = 1;
	for(i=1; i<=n; i++) {
		scanf("%d", &x);
		x -= a;
		for(j=0; j<=5000; j++) {
			d[i][j] += d[i-1][j];
			d[i][j+x] += d[i-1][j];
		}
	}
	printf("%lld", d[n][2500]-1);
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
vi used;
vector<set<int>> G;
void dfs(int v){
    if(used[v]) return;
    used[v] = true;

    for(auto& nv : G[v]){
        dfs(nv);
    }
}

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

    int n, m; cin >> n >> m;
    G.resize(n);
    vi A, B;
    rep(i, m){
        int a, b; cin >> a >> b; a--, b--;
        G[a].insert(b);
        G[b].insert(a);
        A.emplace_back(a);
        B.emplace_back(b);
    }

    int res = 0;
    rep(i, m){
        int a = A[i], b = B[i];
        G[a].erase(b);
        G[b].erase(a);

        used = vi(n);
        dfs(a);
        if(not used[b]){
            res++;
        }

        G[a].insert(b);
        G[b].insert(a);
    }

    cout << res << endl;

    return 0;
}


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

int main() {
    vector<int> N(5);
    rep(i,5) cin >> N.at(i);
    int K; cin >> K;
    for (int i = 0; i < 4; i++) {
        for (int j = i + 1; j < 5; j++) {
            if (abs(N[j] - N[i]) > K) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }
    cout << "Yay!" << endl;
}

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

#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll   long long 
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;


#define md          1000000007
#define fmd         998244353 
#define M           100011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}


ll F[M],iv[M];
void prec(){
    F[0]=iv[0]=1;
    for(int i=1;i<M;++i){
        F[i]=F[i-1]*i%md;F[i]%=md;
        iv[i]=iv[i-1]*exp(i,md-2)%md;iv[i]%=md;
    }
}
ll chose(ll n,ll k){
    if(n<k)return 0;
    ll r=F[n];r=r*iv[k];r%=md;r=r*iv[n-k];return r%md;
}


int solve(){
    ll n,i,j,k,m,x,y,z;
    ll p;
    cin>>n>>k;
    vector<ll> v(n);
    map<ll,ll> st;
    for(i=0;i<n;++i){cin>>v[i];st[v[i]]++;}
    ll ans=0;
    sort(all(v));
    vector<ll> vq;
    for(auto x:st)vq.pb(x.F);
    for(i=0;i<vq.size();++i){
        x=-1;
        ll p=v.size();
        for(;p>=1;p/=2){
            while(x+p<v.size()&&v[x+p]<vq[i])x+=p;
        }
        ++x;
        ll w=(chose(x+st[vq[i]],k)-chose(x,k)+md)%md;
        ans=ans+vq[i]*w%md;ans%=md;
    }
    reverse(all(vq));
    reverse(all(v));
    for(i=0;i<vq.size();++i){
        x=-1;
        ll p=v.size();
        for(;p>=1;p/=2){
            while(x+p<v.size()&&v[x+p]>vq[i])x+=p;
        }
        ++x;
        ll w=(chose(x+st[vq[i]],k)-chose(x,k)+md)%md;
        ans=ans-vq[i]*w%md;ans%=md;
    }
    cout<<ans<<"\n";





	die();

}
 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif

     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

    int t;
    t=1;;
    prec();
    // cin>>t;
 
    while(t--){

        solve();
    }
 
 
 
 


#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

Measured memory_bytes: 9464
#include <bits/stdc++.h>
using namespace std;
int main(){
for(int i=0;;i++){
int a,s;
cin>>a;
char op;
cin>>op;
cin>>s;
if(op=='?') break;
if(op=='+'){
cout<<a+s<<endl;
}
else if(op=='-'){
cout<<a-s<<endl;
}
else if(op=='*'){
cout<<a*s<<endl;
}
else{
cout<<a/s<<endl;
}
}
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    ll n;
    cin >> n;
    vector<ll> v(n,0);
    for(ll i=0;i<n;i++){
        cin>>v[i]
    ;}
    ll counter=0;
    for(ll i=1;i<n-1;i++){
        if(v[i]>v[i-1]&&v[i]<v[i+1])counter++;
        else if(v[i]<v[i-1]&&v[i]>v[i+1])counter++;
    ;}
    cout<<counter<<endl;

    return 0;
}


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

using namespace std;

int main() {
    string str; cin >> str;
    int alphabets[26] = {0};
    for (auto s: str) alphabets[s - 'a'] = 1;
    int offset = -1;
    for (int i = 0; i < 26; i++) {
        if (alphabets[i] == 0) {
            offset = i;
            break;
        }
    }

    if (offset > -1) cout <<  char(97 + offset) << endl;
    else             cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    unsigned long long mass,k,a,b,c,i,j;
   cin>>a;
   for(i=0;i<5;i++){
       cin>>k;
       if(i==0){
           b=k;
           continue;
       }
       else if(k<b)
       b=k;
   }
   c = a/b;
   if(a%b==0){
       cout<<4+c<<endl;
   }
   else
      cout<<5+c<<endl;
    
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/dp/tasks/dp_l

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 3000;
const int A_I_MAX = 1e9;

int N;
int a[N_MAX];

ll dp[N_MAX][N_MAX];

void solve() {
  FOR(k, 1, N) {
    bool sen = ((N - k) % 2 == 0);
    FOR(i, 0, N - k) {
      if (k == 1) {
        if (sen) {
          dp[i][i] = a[i];
        } else {
          dp[i][i] = -a[i];
        }
      } else {
        int j = i + k - 1;
        if (sen) {
          dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j]);
        } else {
          dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j]);
        }
      }
    }
  }
  // DUMP2D(dp, N, N);
  printf("%lld\n", dp[0][N - 1]);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);
}

int main() {
  input();
  solve();
  return 0;
}


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

using namespace std;

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

    int n;
    cin >> n;
    map<pair<int, int>, int> cnt;
    for (int i = 0; i < n; i++) {
        long double x;
        cin >> x;
        long long val = llround(x * 1e9);
        int two = 0, five = 0;
        while (val % 2 == 0) {
            two++; val /= 2;
        }
        while (val % 5 == 0) {
            five++; val /= 5;
        }
        cnt[{two, five}]++;
    }
    long long ans = 0;
    for (auto p1 : cnt) {
        for (auto p2 : cnt) {
            if (p1.first.first + p2.first.first >= 18 && p1.first.second + p2.first.second >= 18) {
                if (p1 < p2) {
                    ans += 1ll * p1.second * p2.second;
                }
                else if (p1 == p2) {
                    ans += 1ll * p1.second * (p1.second - 1) / 2;
                }
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3744