akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
set<int> g[1 + nmax];
int _count[1 + nmax];

int main()
{
  int n;
  cin >> n;
  for(int i = 1;i < n; i++){
    int x, y;
    cin >> x >> y;
    ++x;
    ++y;
    g[x].insert(y);
    g[y].insert(x);
  }

  int _left = n;
  for(int i = 1;i <= n; i++){
    if(g[i].size() == 2){
      set<int>::iterator it = g[i].begin();
      int x = *it;
      it++;
      int y = *it;
      g[i].clear();
      g[x].erase(i);
      g[y].erase(i);
      g[x].insert(y);
      g[y].insert(x);
      _left--;
    }
  }
  if(_left == 2)
    cout << 1;
  else {
    int result = 0;
    for(int i = 1; i <= n; i++)
      if(g[i].size() == 1) {
        _count[*g[i].begin()]++;
        result += (1 < _count[*g[i].begin()]);
      }
    cout << result;
  }
  return 0;
}


Measured memory_bytes: 14720
//保留所有权利。
#include<iostream>
#include<stdio.h>//printするよ
#include<vector>
#include<algorithm>//辞書順はnext_permutationだよ
#include<set>
#include<string>
#include<sstream>
#include<string.h>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swapで数値交換するよ
//END OF LIBRARIES.
#define rt "\n"//改行を最速化させるよ
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define vcin(v) for (int i = 0; i < (v).size(); i++) { cin >> (v)[i]; }
#define sort(s) sort(s.begin(),s.end())
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define cncn int cnt=0
#define smsm int sum=0
#define str srting
#define v vector
#define please return
#define AC 0//おまじないだよ
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
//END OF DEFINE.
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vcha;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
//printf("%02d:%02d:%02d\n", h, m, s);・・・2文字は埋める・h、m、ｓ
//END OF TYPEDEF.

//最大公約数（GCD）を求めるよ
//最小公倍数（LCM）は＜＜　A × B ÷ GCD　 ＞＞で求まるよ

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

//for A以上B未満でI探索 for (int I = A; i <= B; i++)

//string s = to_string(i);

//char→小文字のほうが大きい数値　　&&　その差は32

//大文字→小文字 文字列のn文字目を大文字で出力→ (char)toupper(a[0])

int a = 0, b = 0, c = 0, x = 0, y = 0, z = 0, n = 0, sum = 0, i = 0;
string s = ""; asas; cncn;

int main(void) {
	cin >> a >> b;
	if (a + b >= 10)cout << "error" << rt;
	else cout << a + b << rt;
	please AC;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
A = np.array(list(map(int,input().split())))
mod = 10**9+7

ans = 0
for i in range(len(bin(max(A))[2:])):
	a = (A>>i)&1
	a = np.count_nonzero(a)
	b = n-a
	a *= b
	a = a<<i%mod
	ans = (ans+a)%mod
print(ans)

Measured memory_bytes: 48840
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;

ll GCD(ll a, ll b) {
   if (b == 0) return a;
   return GCD(b, a%b);
}

int main(){
    ll n;
    cin>>n;
    vector<ll>t(n);
    for(int i=0;i<n;i++) cin>>t[i];
    ll ans=1;
    for(int i=0;i<n;i++){
        ans=ans/GCD(ans,t[i])*t[i];
    }
    cout<<ans<<endl;


}



Measured memory_bytes: 256
import java.util.Scanner;

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

	System.out.println(Math.max(Math.max(0,a-w-b),b-w-a));

	}}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
#define pb push_back 
#define in long long
#define inf INT_MAX
#define ninf INT_MIN
#define M 1000000007

int main()
{
   int n,m; cin>>n>>m;
  int a[n]; float s=0;
  for(int i=0;i<n;i++) {cin>>a[i]; s+=a[i];}
  s=s/(4.0*m);int c=0;
  
  for(int i=0;i<n;i++)
  {
    if(a[i]>=s) c++;
  }
  
  if(c>=m) cout<<"Yes"; else cout<<"No";
}


Measured memory_bytes: 256
N, L = map(int, input().split())

taste = [L+i-1 for i in range(1, N+1)]

if 0 in taste:
    select = 0
else:
    select_with_ind = min(enumerate(taste), key = lambda x: abs(x[1]))
    select = select_with_ind[1]
    
print(sum(taste) - select)

Measured memory_bytes: 3060
N = int(input())
#N,K = map(int,input().split())
#N = int(input())
V = list(map(int,input().split()))
V.sort()
N-=1
s=V[0]/(2**N)
V.pop(0)
for i in range(N):
    s+=V[i]/2**N
    N-=1

print(s)


Measured memory_bytes: 3060
s = str(input())
n = int(len(s))
p = s[0 : n//2]
s = s[n//2 : n+1]
hug = 0
s = s[len(s)::-1]
for i, m in zip(s, p):
  if i!=m:
    hug+=1
      
print(hug)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        char board[60][60];
        int num[30] = {0};
        int h, w;
        cin >> h >> w;
        for (int j = 0; j < h; ++j) {
            scanf("%s", board[j]);
            for (int k = 0; k < w; ++k) {
                ++num[board[j][k] - 'A'];
            }
        }
        bool flag = true;

        while (flag) {
            flag = false;
        for (int j = 0; j < 30; ++j) {
            if (!num[j])
                continue;
            
            int up = 100, dw = -1, lf = 100, ri = -1;
            for (int k = 0; k < h; ++k) {
                for (int l = 0; l < w; ++l) {
                    if (board[k][l] == j + 'A') {
                        lf = min(lf, l);
                        dw = max(dw, k);
                        up = min(up, k);
                        ri = max(ri, l);
                    }
                }
            }
            for (int k = up; k <= dw; ++k) {
                for (int l = lf; l <= ri; ++l) {
                    if (board[k][l] != j + 'A' && board[k][l] != '#') {
                        goto A;
                    }
                }
            }
            for (int k = up; k <= dw; ++k) {
                for (int l = lf; l <= ri; ++l) {
                    if (board[k][l] == j + 'A') {
                        board[k][l] = '#';
                        --num[j];
                        flag = true;
                    }
                }
            }
            
        A:
            continue;

        }
        }
        for (int j = 0; j < h; ++j) {
            for (int k = 0; k < w; ++k) {
                if (board[j][k] != '.' && board[j][k] != '#'){
                    printf("SUSPICIOUS\n");
                    goto B;
                }
            }
        }
        printf("SAFE\n");
    B:
        continue;
    }

    return 0;
}

Measured memory_bytes: 1148
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double total = 0;
		for (int i = 0; i < n; i++) {
			double x = sc.nextDouble();
			String u = sc.next();
			if (u.equals("JPY")) {
				total += x;
			} else {
				total += x * 380000.0;
			}
		}
		System.out.println(java.math.BigDecimal.valueOf(total).toPlainString());
	}
}


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

struct Node{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;



// ここからプロトタイプ宣言
void insert(int k);
Node* find(Node *u, int k);
void inOrder(Node *u);
void preOrder(Node *u);
// ここまでプロトタイプ宣言

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

	int x;
	for(int i=0;i<n;i++){
		cin>>com;
		if(com=="insert"){
			cin>>x;
			insert(x);
		}else if(com=="print"){
			inOrder(root);
			printf("\n");
			preOrder(root);
			printf("\n");
		}else if(com[0]=='f'){
			cin>>x;
			Node *t = find(root,x);
			if(t!=NIL)
				printf("yes\n");
			else
				printf("no\n");
			
		}
	}

	return 0;
}


//---------------------//
void insert(int k){
	Node *y = NIL;	// xの親
	Node *x = root;
	Node *z;

	z = (Node*)malloc(sizeof(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 の親を探してる？
		// 見つけた親を、y に代入？
	}

	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)return;

	inOrder(u->left);
	printf(" %d",u->key);
	inOrder(u->right);
}

void preOrder(Node *u){
	if(u==NIL)return;

	printf(" %d",u->key);
	preOrder(u->left);
	preOrder(u->right);
}


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



Measured memory_bytes: 22008
#include<stdio.h>
#include<vector>
using namespace std;
vector<int>a[100];
int n,m,ans,b[100];
int vis[100];
void dfs(int u,int d) {
	b[d]=u;
	vis[u]=1;
	if(d==n) {
		ans++;
	}
	for(int i=0; i<a[u].size(); i++) {
		if(vis[a[u][i]]==0) {
			dfs(a[u][i],d+1);
			vis[a[u][i]]=0;
		}
	}
}
int main() {
	int i,v1,v2;
	scanf("%d%d",&n,&m);
	for(i=0; i<m; i++) {
		scanf("%d%d",&v1,&v2);
		a[v1].push_back(v2);
		a[v2].push_back(v1);
	}
	dfs(1,1);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y ,&r);
    
    if((x+r)>W||(x-r)<0||(y+r)>H||(y-r)<0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    
return 0;

}



Measured memory_bytes: 2104
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int A, B; cin >> A >> B;
	string S; cin >> S;

	if(S[A] != '-'){
		cout << "No" << endl;
		return 0;
	}else{
		REP(i,A) if(S[i] < '0' or S[i] > '9'){
			cout << "No" << endl;
			return 0;
		}
		REP(i,B) if(S[A+i+1] < '0' or S[A+i+1] > '9'){
			cout << "No" << endl;
			return 0;
		}
	}


	cout << "Yes" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  int n, x;
  int a[100000];
  cin >> n;
  for(int i = 0; i < n; i++ ){
    cin >> x;
    a[x-1] = i+1;
  }
  for(int i = 0; i < n-1; i++){
    cout << a[i] << " "; 
  }
  cout << a[n-1];
}

Measured memory_bytes: 1152
import java.util.*;
import java.io.*;
import java.math.BigInteger;

 
public class Main implements Runnable {
  static Scanner in;
  // static FastReader in;
  static PrintWriter out;
  static int[][] dirs8 = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {-1, 1}, {1, -1}};
  static int[][] dirs = {{0, -1}, {1, 0}, {0, +1}, {-1, 0}};
 
  static int[][] E;
  // static List<int[]>[] adj;
  static List<Integer>[] adj;
  static int[] vis;
 
  static long INFL = (long) 1e15 + 7;
  static int INF = (int) 1e7 + 9;
 
  static int T, n, m, k, count;
  static boolean flag;
  static int[] a, b;
  static int[][] map;

  static int mod = 998244353;
 
  static void solve() throws Exception {
    int a = in.nextInt();
    int b = in.nextInt();
    long g = (long) gcd(a, b);
    long res = g * (a / g) * (b / g);
    out.println(res);

  }

  static int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
  }


  public static void main(String[] args) throws Exception {
 
    in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    // in = new FastReader();
    out = new PrintWriter(System.out);
 
    // int T = in.nextInt();
    // for (int tt = 1; tt <= T; tt++) {
    //   // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    //   // t.start();
    //   // t.join();
    //   solve();
    // }
 
    // // Thread t = new Thread(null, new Main(), "Main", 1 << 28);
    // // t.start();
    // // t.join();
    solve();
 
    out.flush();
    out.close();
  }
 
  @Override
  public void run() {
    try {
      solve();
    } catch (Exception e) {
      e.printStackTrace(); 
    }
  }
 
  static class FastReader {
    public BufferedReader br; 
    StringTokenizer st; 
    public FastReader() {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; 
    }
  }

  static void as(boolean result) throws Exception {
    if (!result) {
      throw new Exception();
    }
  }

  static int modInverse(int a, int m) { 
    int m0 = m; 
    int y = 0, x = 1; 
    if (m == 1) {return 0;} 
    while (a > 1) { 
      // q is quotient 
      int q = a / m; 
      int t = m; 
      // m is remainder now, process 
      // same as Euclid's algo 
      m = a % m; 
      a = t; 
      t = y; 
      // Update x and y 
      y = x - q * y; 
      x = t; 
    } 
    // Make x positive 
    if (x < 0) 
      x += m0; 
    return x; 
  } 
} 

Measured memory_bytes: 21716
#include<stdio.h>
int main(){

int H,W;
int i,j;

while(1){
scanf("%d %d",&H,&W);
if(H==0&&W==0) break;
for(i=0;i<H;i++){
   for(j=0;j<W;j++){
     if(i==0||i==H-1||j==0||j==W-1){
     printf("#");
     }else{
     printf(".");
     }
     }
     printf("\n");
     }
     printf("\n");
     }
     return 0;
     }


Measured memory_bytes: 2028
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    int cnt = 0;
    REP(i,0,n) cnt += min(a[i], k - a[i]);
    cout << cnt * 2 << endl;
}

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

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

using namespace std;

#define IO ios_base::sync_with_stdio(0);cin.tie(0);

int main()
{
  IO;
	int n; cin >> n;
	int res = 1e9 + 7;
	for (int i = 0; i <= n; ++i) {
	int count1 = 0, count2 = 0;
	int num = i;
	while (num > 0) {
		count1 += num % 6;
		num /= 6;
	}
	num = n - i;
	while (num > 0) {
		count2 += num % 9;
		num /= 9;
	}
	res = min(res, count1 + count2);
	}
	cout << res << endl;
	
 
  return 0;
}

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

using namespace std;
#define int long long
#define double long double
#define all(a) a.begin(), a.end()

template <typename T1, typename T2> inline void chkmax(T1 & x, const T2 & y) {if (y > x) x = y;}
template <typename T1, typename T2> inline void chkmin(T1 & x, const T2 & y) {if (y < x) x = y;}

void read() {
	int a, b, c;
	cin >> a >> b >> c;
	c -= min(a - b, c);
	cout << c << endl;
}

void run() {

}

void write() {

}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int n,ans=0;
    cin>>n;
    vector<int> a(n);
    
    for(int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    
    for(int i = 0; i < n; i++)
    {
        
        for(int j = 0; j < i; j++)
        {
            ans=max(ans,abs(a[i]-a[j]));
        }
    }
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>


typedef long double ld;
typedef long long ll;
using namespace std;
const ll MX=5e6+9;
const ld pi = acos(-1);
const ll mod = 1e8;

//bool cmp ( int a,int b ) { return a>b; }

ll po ( ll a , ll b )
{
    if ( b==0 ) { return 1; }
    ll x = po ( a , b/2 );
    x *= x%mod;
    if ( b%2 ) { x*=a%mod; }
    return x%mod;
}

ll gcd (  ll a , ll b )
{
    if ( b==0 ) return a;
    else { gcd( b , a%b ); }
}
bool cmp ( int a , int b ) { return (a>b); }
int dx[]={ 0 , 0 , -1 , 1 , 1 , -1 , -1 , 1 };
int dy[]={ 1 , -1 , 0 , 0 , 1 , -1 , 1 , -1 };
ll a[MX],b[MX],c[MX];
int n,m,l;


ll bs ( ll x , ll id )
{
    ll st,en,mid;
    if ( id==2 )
    {
        st=0,en=m;
    }
    else { st=0,en=l; }
    ll ans=0;
    if ( id==2 ){
    ans=m-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( b[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    else
    {
    ans=l-1;
    while ( st<=en )
    {
        mid = st+(en-st)/2;
        if ( c[mid]>=x ) { ans=mid; en=mid-1; }
        else { st=mid+1; }
    }
    }
    return ans;



}

int main()
{
    string s;
    cin>>s;
    string t;
    for ( int i=0 ; i<s.length() ; i++ )
    {

        if ( s[i]==',' ) { cout<<t<<" "; t.clear(); continue;}
        t += s[i];
    }

    cout<<t;


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

using namespace std;
using P = pair<int, int>;
using T = tuple<long, long, long>;

long long MOD = 1000000007;
long long dp[100005][4];

int main() {
	long long N,K;
	cin >> N >> K;
	vector<long long>A(N);
	for (int i = 0; i < N; ++i)cin >> A[i];
	
	vector<long long>small(N);
	for (int i = 0; i < N;++i) for (int j = 0; j < i; ++j) if (A[i] < A[j])small[i]++;

	vector<long long>small2(N);
	for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) if (A[i] < A[j])small2[i]++;

	long long ans = 0;
	long long k = ((K * (K - 1)) / 2) % MOD;
	for (int i = 0; i < N; ++i) {
		ans = (ans + ((small[i] * K) % MOD)) % MOD;
		ans = (ans + ((small2[i] * k) % MOD)) % MOD;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int N , Q;
int a[200010] , b[200010];
int p[200010],x[200010];
vector<int> V[200010],num(200010),ans(200010);
bool flag[200010];
int root = 1,cnt[200100] = {};

void solve(int i,int pred){
  	cnt[i] += cnt[pred];
    REP(j,V[i].size()){
        if(V[i][j] != pred)solve((int&)V[i][j],(int&)i);
    }
}

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    cin >> N >> Q;
    REP(i,N-1){
        cin >> a[i] >> b[i];
        V[a[i]].pb(b[i]);
      	V[b[i]].pb(a[i]);
        flag[b[i]] == false;
    }
    REPP(i,1,N+1){
        if(flag[i] == true){
            root = i;
            break;
        }
    }
    REP(i,Q){
        cin >> p[i] >> x[i];
        cnt[p[i]] += x[i];
    }
  	int m = 0;
    solve(root,m);
    REPP(i,1,N+1){
        cout << cnt[i] << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 28160
#include <bits/stdc++.h>
#define Maxn 300007
using namespace std;
int n;
int a[Maxn];
long long s[Maxn];
map<long long,int> mp;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	s[0]=0;
	for (int i=1;i<=n;i++)
		s[i]=s[i-1]+a[i];
	long long ans=0;
	for (int i=0;i<=n;i++)
	{
		ans+=mp[s[i]];
		++mp[s[i]];
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int res = 0;
    rep(i,n) res += a[i];

    int mn = INF;
    int idx = -1;
    rep(i,n){
        if(abs(n*a[i]-res)<mn){
            mn = abs(n*a[i]-res);
            idx = i;
        }
    }
    cout << idx << endl;
    return 0;
}

Measured memory_bytes: 3564
#define MYDEBUG
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <cstdio>
#include <queue>
#include <stack>
#include <cstring>

#ifdef MYDEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define umap unordered_map
using namespace std;

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}
const int maxw = 801;
int h, w, k;
queue<int> wi, wj;
int di[4] = { -1, 0, 1, 0 };
int dj[4] = { 0, 1, 0, -1 };
bool v[maxw][maxw];
char g[maxw][maxw];

void bfs(int si, int sj) {
  queue<int> qi, qj, qn;
  qi.push(si);
  qj.push(sj);
  qn.push(0);
  v[si][sj] = true;
  while (!qi.empty()) {
    int i = qi.front(), j = qj.front(), n = qn.front();
    qi.pop();
    qj.pop();
    qn.pop();
    wi.push(i);
    wj.push(j);
    if (n == k)
      continue;
    for (int m = 0; m < 4; ++m) {
      int ni = i + di[m], nj = j + dj[m];
      if (0 <= ni && ni < h && 0 <= nj && nj < w && !v[ni][nj] && g[ni][nj] != '#') {
        v[ni][nj] = true;
        qi.push(ni);
        qj.push(nj);
        qn.push(n + 1);
      }
    }
  }
}

void solve() {
  cin >> h >> w >> k;
  int si, sj;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> g[i][j];
      if (g[i][j] == 'S') {
        si = i;
        sj = j;
      }
    }
  }
  memset(v, 0, sizeof(v));
  wi = queue<int>();
  wj = queue<int>();
  bfs(si, sj);
  int ans = h + w + 1;
  while (!wi.empty()) {
    int i = wi.front(), j = wj.front();
    wi.pop();
    wj.pop();
    if (i == 0 || i == h - 1 || j == 0 || j == w - 1) { //最初のk歩でゴールできるなら1ターン
      cout << 1 << endl;
      return;
    }
    int height = min(abs(h - 1 - i), i); //一番近い壁(上下で)
    int width = min(abs(w - 1 - j), j); //一番近い壁(左右で)
    int d = min(height, width); //ゴールまでの最短経路の長さ
    ans = min(ans, (d + k - 1) / k + 1); //k歩動いてから, d歩必要. そこからはd/k(切り上げ)ターンで到着. 予めk歩動いた時点で+1
  }
  cout << ans << endl;
}

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


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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  long double N, D;
  cin >> N >> D;
  int ans = 0;
  for(int i = 0; i < N; i++){
    int x, y;
    cin >> x >> y;
    if(sqrt(pow(x,2) + pow(y,2)) <= D){
      ans++;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 3744
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		string[] args;
		
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int Q = Int32.Parse(args[1]);
		
		string S = Console.ReadLine();
		int[] csum = new int[N+1];
		csum[0] = 0;
		
		int counter = 0;
		bool aFlag = false;
		for(int i = 0; i < N; i++)
		{			
			switch(S[i])
			{
				case 'A':
					aFlag = true;
					break;
					
				case 'C':
					if(aFlag)
						counter++;					
					aFlag = false;
					break;
					
				default:
					aFlag = false;
					break;
			}
			csum[i+1] = counter;
		}
		
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < Q; i++)
		{
			args = Console.ReadLine().Split(' ');
			int l = Int32.Parse(args[0]);
			int r = Int32.Parse(args[1]);
			sb.AppendLine((csum[r] - csum[l]).ToString());
		}
		Console.WriteLine(sb);			
	}
}





Measured memory_bytes: 19912
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ms = 0

for i in range(n):
    if a[i]>=b[i]:
        a[i] = a[i]-b[i]
        ms += b[i]
        b[i] = 0
    else:
        b[i] = b[i] - a[i]
        ms += a[i]
        a[i] = 0

    if a[i+1]>=b[i]:
        a[i+1] = a[i+1]-b[i]
        ms += b[i]
        b[i] = 0
    else:
        b[i] = b[i] - a[i+1]
        ms += a[i+1]
        a[i+1] = 0

print(ms)


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define int ll

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

signed main()
{
    int n;
    string s;
    cin >> n >> s;
    int x = 0;
    int ans = x;
    rep(i, n) {
        if(s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
char min(string s){
char min='z';
for(int i=0;i<s.length();i++){
if(s[i]<min) min=s[i];
}
return min;
}
char max(string s){
char max='a';
for(int i=0;i<s.length();i++){
if(s[i]>max) max=s[i];
}
return max;
}

int main(){
string s1;
string s2;
cin>>s1>>s2;
bool f=0;
for(int i=0;i<s1.length();i++){
if(s1[i]!=s2[i])  {f=1;


}
}
if(f==0){
    if(s1.length()<s2.length()){
        cout<<"Yes";
        return 0;
    }
    else {

        cout<<"No";
        return 0;
    }
}




if(min(s1)<max(s2)) cout<<"Yes";
else cout<<"No";


}


Measured memory_bytes: 256
// edpc_f
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string s, t;
    cin >> s >> t;

    vector<vector<ll>> dp;
    dp.assign(s.size()+1, vector<ll>(t.size()+1, 0));

    REP(i, s.size()){
        REP(j, t.size()){
            if (s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    int i = s.size()-1;
    int j = t.size()-1;

    string ans = "";
    auto tmp = dp;
    while(ans.size() < dp[s.size()][t.size()]){

        if (dp[i+1][j+1] == dp[i+1][j]){
            j--;
        } else if (dp[i+1][j+1] == dp[i][j+1]){
            i--;
        } else{
            ans = s[i] + ans;
            i--; j--;
        }

    }

    print(ans);

    return 0;
}


Measured memory_bytes: 141184
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return float64(i)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

const Mod = 1000000007

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	sc.Split(bufio.ScanWords)

	n := readInt()
	a := make([]int64, n)

	for i := 0; i < n; i++ {
		a[i] = readInt64()
		if a[i] == 0 {
			fmt.Println("0")
			return
		}
	}

	var ans int64 = 1
	for i := 0; i < n; i++ {
		ans *= a[i]
		if ans > 1e18 || ans < a[i] {
			fmt.Println("-1")
			return
		}
	}
	fmt.Println(ans)
}


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

namespace ABC149
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            string[] st = Console.ReadLine().Split(' ');
            string ans = "";
            ans += st[1];
            ans += st[0];
            Console.WriteLine(ans);
        }

        public static void b()
        {
            long[] abk = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            long a = abk[0], b = abk[1], k = abk[2];
            long a1 = a;
            a -= k;
            if(a < 0)
            { a = 0; }
            k -= a1;
            if(k < 0)
            { k = 0; }
            b -= k;
            if(b < 0)
            { b = 0; }
            Console.WriteLine("{0} {1}", a, b);
        }

        public static void c()
        {
            long x = long.Parse(Console.ReadLine());
            long ans = x;
            while(true)
            {
                if(x % 2 == 0)
                {
                    x++;
                    continue;
                }
                if (x != ans)
                { break; }
                else
                { x++; }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define pii pair<int, int>
#define MP make_pair
#define fi first
#define se second
using namespace std;
typedef long long LL;
const int MAXN = 200005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

int n, vis[MAXN];
pii a[MAXN];

void init() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i * 2 - 1].fi);
		a[i * 2 - 1].se = i;
		read(a[i * 2].fi);
		a[i * 2].se = -i;
	}
	sort(a + 1, a + n * 2 + 1);
}

void solve() {
	LL ans = 0;
	int cnt1 = 0, cnt2 = 0, cnt3 = 0;
	for (int i = 1; i <= n; ++i) {
		ans += a[i].fi;
		int j = a[i].se;
		if (j > 0) {
			++cnt1;
			cnt3 += (++vis[j] == 2);
		} else {
			++cnt2;
			cnt3 += (++vis[-j] == 2);
		}
	}
	if (cnt3 || (cnt1 == n || cnt2 == n)) {
//printf("type 1\n");
		printf("%lld\n", ans); return;
	}
	ans += a[n + 1].fi - a[n].fi;
	(a[n].se > 0)? --cnt1 : --cnt2;
	(a[n + 1].se > 0)? ++cnt1 : ++cnt2;
	if (abs(a[n].se) != abs(a[n + 1].se) || cnt1 == n || cnt2 == n) {
//printf("type 2\n");
		printf("%lld\n", ans); return;
	}
	printf("%lld\n", min(ans - a[n - 1].fi + a[n].fi, ans - a[n + 1].fi + a[n + 2].fi));
}

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


Measured memory_bytes: 5620
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        for(;;){
            C = Attack(C,B);
            if(C<=0){
                System.out.println("Yes");
                break;
            }
            A = Attack(A,D);
            if(A<=0){
                System.out.println("No");
                break;
            }
        }
    }
    public static int Attack(int H, int A){
        H -= A;
        return H;
    }
}


Measured memory_bytes: 35696
N = int(input())

X = list(map(int,input().split()))

a = max(X)

b = a/2
t = min([i for i in X if i>=b])
s = max([i for i in X if i<=b])
if t-b >= b-s:
  print(a,s)
elif t-b < b-s:
  print(a,t)

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

int main() {
	vector<int> v;
	int a, b, c;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);

	sort(v.begin(), v.end());
	printf("%d %d %d", v[0], v[1], v[2]);

	cout << endl;
	return 0;
}

Measured memory_bytes: 3240
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
ll fact[N];
ll invfact[N];
ll inv[N];
void factorialsComputation()
{
    inv[0]=inv[1]=1;
    fact[0]=fact[1]=1;
    invfact[0]=invfact[1]=1;
    for(int i=2;i<N;i++)
    {
        inv[i]=(inv[mod%i]*(mod-mod/i))%mod;
        fact[i]=(fact[i-1]*i)%mod;
        invfact[i]=(invfact[i-1]*inv[i])%mod;
    }
}
ll ncr(ll n,ll r)
{
    ll ans=fact[n]*invfact[r];
    ans%=mod;
    ans*=invfact[n-r];
    ans%=mod;
    return ans;
}
void solve()
{
    ll b,w;
    cin>>b>>w;
    ll blackgone[b+w+1]={0};
    ll whitegone[b+w+1]={0};
    ll den=inv[2];
    whitegone[w]=power(den,w);
    for(int i=w+1;i<=b+w;i++)
    {
        whitegone[i]=whitegone[i-1]+(ncr(i-1,w-1)*power(den,i))%mod;
        whitegone[i]%=mod;
    }
    blackgone[b]=power(den,b);
    for(int i=b+1;i<=b+w;i++)
    {
        blackgone[i]=blackgone[i-1]+(ncr(i-1,b-1)*power(den,i))%mod;
        blackgone[i]%=mod;
    }
    for(int i=1;i<=b+w;i++)
    {
        ll ans=0;
        ll temp1=whitegone[i-1];
        ans+=temp1;
        ll temp2=blackgone[i-1];
        ll now=1+2*mod-temp1-temp2;
        now%=mod;
        now*=den;
        now%=mod;
        ans+=now;
        ans%=mod;
        cout<<ans<<'\n';
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    factorialsComputation();
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 30256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    ll D, E, F;
    cin>>A>>B>>C>>D>>E>>F;
    long double comp = -1e-9;
    P ans = {A*100,0};
    for(int i = 0; i*A*100 <= F; ++i){
        for(int j = 0; i*A*100 + j*B*100 <= F; ++j){
            ll water = i*A*100 + j*B*100;
            if(water == 0) continue;
            for(int k = 0; k*C <= F - water; ++k){
                for(int l = 0; k*C + l*D <= F - water; ++l){
                    ll salt = k*C + l*D;
                    //cout<<water<<' '<<salt<<endl;
                    if(E*water/100 < salt) break;
                    long double temp = (100*salt), div = water + salt;
                    temp /= div;
                    if(comp + EPS < temp){
                        comp = temp;
                        ans = mp(water, salt);
                    }
                    //cout<<' '<<water<<' '<<salt<<endl;
                }
            }
        }
    }
    cout<<ans.fi + ans.se<<' '<<ans.se<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	string a, b;
	cin >> a >> b;
	int sum = a.size() + b.size();
	int ia = 0, ib = 0;
	for(int i = 0;i < sum;i++){
		if(i % 2 == 0){
			cout << a[ia];
			ia++;
		}else{
			cout << b[ib];
			ib++;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
string divide[4] = {"dream", "dreamer", "erase", "eraser"};

    // 後ろから解くかわりにすべての文字列を「左右反転」する
    reverse(s.begin(), s.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for(int i=0;i<s.size();){
    bool can2 = false;
    for(int j=0;j<4;j++){
      string d = divide[j];
      if(s.substr(i,d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }
  
  if(can) cout<< "YES"<<endl;
  else cout << "NO"<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <float.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j, k;
	long int h, w, a, b;
	long int count = 0;
	long int flg = 0;
	long int flgs = 0;
	long int flgfirst = 0;
	long int masu[1001][1001];
	
	scanf("%ld%ld%ld%ld", &h, &w, &a, &b);
	
	for(i = 1; i <= h; i++) {
		for(j = 1; j <= w; j++) {
			if (i <= h - b)
			{
				if (j <= w - a)
				{
					masu[i][j] = 1;
				}
				else
				{
					masu[i][j] = 0;
				}
			}
			else
			{
				if (j <= w - a)
				{
					masu[i][j] = 0;
				}
				else
				{
					masu[i][j] = 1;
				}
			}
		}
	}
	
	for (i = 1; i <= h; i++)
	{
		for (j = 1; j <= w; j++)
		{
			printf("%ld", masu[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

const ll N=1e3+10;
ll n,m;
vector<set<ll>> G(N),GG(N);

int main() {
  cin >> n >> m;
  for(ll i=0;i<m;i++) {
    ll a,b;
    cin >> a >> b;
    a--,b--;
    G[a].insert(b);
    GG[b].insert(a);
  }
  ll ans=inf;
  vec ansv(n);
  for(ll i=0;i<n;i++) {
    priority_queue<pll> q;
    ll id=-1;
    vec d(n,-1);
    q.push({0,i});
    while(q.size()) {
      ll f=q.top().second;
      ll td=q.top().first;
      q.pop();
      if(d[f]>-1) continue;
      d[f]=td;
      for(ll t:G[f]) {
        ll nd=td+1;
        if(t==i) {
          id=f;
          break;
        }
        q.push({nd,t});
      }
      if(id>-1) break;
    }
    if(id>-1) {
      if(ans>d[id]+1&&d[id]) {
        ans=d[id]+1;
        ll j=0;
        while(1) {
          ansv[j]=id+1;
          j++;
          if(id==i) break;
          for(ll t:GG[id]) {
            if(d[t]+1==d[id]) {
              id=t;
              break;
            }
          }
        }
      }
    }
  }
  if(ans==inf) ans=-1;
  cout << ans << endl;
  for(ll i=0;i<ans;i++) {
    cout << ansv[ans-i-1] << endl;
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  int* vec = new int[5];
  for(int i = 0; i< 5; ++i)
  {
    cin >> x;
    vec[i] = x;
  }
  int k;
  cin >> k;
bool salir = false;


for(int i = 0; i< 4; ++i)
{
  for( int r = i+1; r < 5; ++r )
  {
    if(vec[r]-vec[i] > k)
    {
      salir = true;
      break;
    }
  }
  if(salir)
  break;
}

if(salir)
cout << ":(";
else cout << "Yay!";
  delete[] vec;
  return 0;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-09-19
**/

#include <bits/stdc++.h>
using namespace std;

const int MOD = 998244353;

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

Measured memory_bytes: 6344