akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans;

    ans = ((h2 - h1) * 60) + (m2 - m1) - k;
    // if (h1 <= h2)
    // {
    //     if (m2 >= m1)
    //     {
    //         ans = (h2 - h1) * 60;
    //         ans += (m2 - m1);
    //         ans -= k;
    //     }
    //     else if (m2 < m1)
    //     {
    //         ans = (h2 - h1 - 1) * 60;
    //         ans += (60 - m1);
    //         ans -= k;
    //     }
    // }
    // else if
    // {
    //     if (m2 >= m1)
    //     {
    //         ans = ((24 - h1) + h2) * 60;
    //         ans += (m2 - m1);
    //         ans -= k;
    //     }
    //     else if (m2 < m1)
    //     {
    //         ans = ((24 - h1) + h2 - 1) * 60;
    //         ans += (60 - m1);
    //         ans -= k;
    //     }
    // }
    cout
        << ans << endl;
    return (0);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int A, B;
  cin >> A >> B;
  if (A %2 != B %2)
  {
    cout << "IMPOSSIBLE" << endl;
  }
  else
  {
    long long int ans = (A + B) / 2;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
//<60 >62
	public static void main(String[] args) {
			//String S=sc.next();
			//int N=sc.nextInt();
			//int v[]=new int[N];
			//for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int v[]=new int[N];
		for(int i=0;i<N;i++) {
			v[i]=sc.nextInt();
		}
		
		
		boolean x=true;
		for(int i=N-1;i>0;i--) {
			if(v[i]<v[i-1]) {
				v[i-1]--;
			}
			if(v[i]<v[i-1]) {
				x=false;
				break;
			}
		}
		if(x)p("Yes");
		else p("No");
		
	}
	static int v(int a) {
		return a*(a-1)/2;
	}

	
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 51028
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define N 10001
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define IFNTY 1 << 21

vector<pair<int, int> > G[N];
int color[N], d[N], p[N];

int pirm (int n) {
  priority_queue<pair<int, int> > PQ;
  int mincost, u;

  for (int i = 0; i < n; i++) {
    color[i] = WHITE;
    d[i] = IFNTY;
  }

  d[0] = 0;
  p[0] = -1;
  PQ.push(make_pair(0, 0));

  while (PQ.size()) {
    mincost = PQ.top().first * -1;
    u = PQ.top().second;
    PQ.pop();

    color[u] = BLACK;

    for (int j = 0; j < G[u].size(); j++) {
      pair<int, int> v = G[u][j];
      if (color[v.second] != BLACK && v.first < d[v.second]) {
        d[v.second] = v.first;
        p[v.second] = u;
        PQ.push(make_pair(v.first * -1, v.second));
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
    ans += d[i];
  return ans;
}

int main () {
  int V, E;

  cin >> V >> E;

  int s, d, c;

  for (int i = 0; i < E; i++) {
    cin >> s >> d >> c;
    G[s].push_back(make_pair(c, d));
    G[d].push_back(make_pair(c, s));
  }

  cout << pirm(V) << endl;

  return 0;
}


Measured memory_bytes: 6280
def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.buffer.readline

    N = int(input())
    A = []
    for _ in range(N):
        A.append(list(map(int, input().split())))

    adj = defaultdict(list)
    in_num = defaultdict(int)
    for i in range(N):
        for j in range(N-2):
            x1 = x2 = i+1
            y1 = A[i][j]
            y2 = A[i][j+1]
            if x1 > y1:
                x1, y1 = y1, x1
            if x2 > y2:
                x2, y2 = y2, x2
            adj[x1*(N+1)+y1].append(x2*(N+1)+y2)
            in_num[x2*(N+1)+y2] += 1
    st = []
    ng = (N * (N - 1)) // 2
    for i in range(1, N+1):
        for j in range(i+1, N+1):
            if in_num[i*(N+1)+j] == 0:
                st.append(i*(N+1)+j)
                ng -= 1
    ans = 0
    while st:
        ans += 1
        st_new = []
        for par in st:
            for child in adj[par]:
                if in_num[child] == 1:
                    st_new.append(child)
                    ng -= 1
                in_num[child] -= 1
        if st_new:
            st = st_new
        else:
            break

    if ng:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


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

#define ll long long

using namespace std;

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

	int n, m; cin >> n >> m;
	if (n%m == 0) cout << "0";
	else cout << "1";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
int main()
{
    int n, debt = 100000;
    cin >> n;
    for (int i = 0; i < n; i++) {
        debt *= 1.05;
        if (debt % 1000 != 0) {
            debt += 1000 - debt % 1000;
        }
    }
    cout << debt << endl;
    return 0;
}

Measured memory_bytes: 3096
tem = list(map(int,input().split()))
n = tem[0]
k = tem[1]
s = [i for i in input()]


count = 0
for i in range(n-1):
    if(s[i]!=s[i+1]):
        count += 1
    else:
        pass

tem_h = n - 1 - count

if((int(count/2)+count%2)>k):
    h = tem_h + 2*k
elif((int(count/2)+count%2)<=k):
    h = n-1

print(h)

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

D = [list(map(int,input().split())) for i in range(N)]

E = [D[i][0]==D[i][1] for i in range(N)]
flag = False
for i in range(N-2):
    if E[i] and E[i+1] and E[i+2]:
        flag=True
        break

if flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62436
#include <stdio.h>
#include <math.h>
#define N 500000

int cnt=0;

void merge(int *A,int left,int mid,int right){
  int n1 = mid-left;
  int n2 = right-mid;
  int i,j,k;
  int L[N],R[N];
  
  for(i=0;i<=n1-1;i++){
    L[i] = A[left+i];
  }
  for(i=0;i<=n2-1;i++){
    R[i] = A[mid+i];
  }
  L[n1] = INFINITY;
  R[n2] = INFINITY;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
    cnt++;
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
    }
    else {
      A[k] = R[j];
      j++;
    }
  }
}
void mergeSort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid = (left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
int main(){
  int n,S[N],i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  mergeSort(S,0,n);
  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",S[i]);
    else printf("%d ",S[i]);
  }

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



Measured memory_bytes: 5644
#include <iostream>
#include <queue>

using namespace std;

struct restaurant {
    int index, point;
    string s;
    bool operator<(const restaurant& rhs) const
    {
        if(s == rhs.s) {
            return point < rhs.point;
        } else {
            return s > rhs.s;
        }
    }
};

int main() {
    priority_queue<restaurant> p;
    int N; cin >> N;

    for(int i = 0; i < N; i++) {
        string s; int point; cin >> s >> point;
        p.push({i+1, point, s});
    }

    for(int i = 0; i < N; i++) {
        auto f = p.top(); p.pop();
        cout << f.index << endl;
    }
}



Measured memory_bytes: 888
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk(a, b) make_pair(a, b)
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int h, w, d, q, sum[90010];
pair<int, int>xy[90010];

signed main()
{
    cin >> h >> w >> d;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a;
            cin >> a;
            xy[a] = mk(i, j);
        }
    }
    for(int i = d + 1; i <= h * w; i++){
        sum[i] += sum[i - d] + abs(xy[i].first - xy[i - d].first) + abs(xy[i].second - xy[i - d].second);
    }
    cin >> q;
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << endl;
    }


    return 0;
}
/*


*/


Measured memory_bytes: 3200
<?php
define('MOD', pow(10, 9) + 7);

fscanf(STDIN, "%d %d", $N, $K);

$ans = 0;
for ($i = $K; $i <= $N + 1; $i++) {
    $ret = calc($N, $i);
    $ans += $ret;
    $ans %= MOD;
}
printf("%d", $ans);

function calc($N, $K) {
    return ($N + $N - $K - $K + 2) * $K / 2 + 1;
}


Measured memory_bytes: 16200
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int minx=0, miny=0, maxx, maxy;
	int n;
	cin >> maxx >> maxy >> n;
	REP(i, n) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			minx = max(minx, x);
		}
		else if(a==2){
			maxx = min(maxx, x);
		}
		else if (a == 3) {
			miny = max(miny, y);
		}
		else if (a == 4) {
			maxy = min(maxy, y);
		}
	}
	int ans = (maxx - minx);
	if (ans > 0)
		ans *= (maxy - miny);
	cout << max(0, ans) << endl;
}

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

int main() {
	int n, x;
	cin >> n;
	for (int lop = 0; lop < n; lop++) {
		int a = 0, b = 0;
		bool f = true;
		for (int i = 0; i < 10; i++) {
			cin >> x;
			if (f) {
				if (a < x && b < x) {
					if (a < b) {
						b = x;
						continue;
					}
					a = x;
					continue;
				}
				if (a < x) {
					a = x;
					continue;
				}
				if (b < x) {
					b = x;
					continue;
				}
				f = false;
			}
		}
		if (f)
			cout << "YES\n";
		else
			cout << "NO\n";
		//cout << (f ? "YES\n" : "NO\n");
	}
	return 0;
}


Measured memory_bytes: 3032
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
kind=[]
count=1
for i in range(len(a)-1):
  if(a[i]==a[i+1]):count+=1
  else:
    kind.append(count)
    count=1
kind.append(count)
kind.sort()
change=0
for i in range(k):
  if(len(kind)!=0):change+=kind.pop()
print(n-change)


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

typedef long long LL;

const int N=1500,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n;
char s[N+9][N+9];

void into(){
  scanf("%d",&n);
  for (int i=1;i<n;++i)
	scanf("%s",s[i]+1);
}

struct graph{
  
  int n,e[N+9][N+9];
  
  void Get_n(int N){
	n=N;
	for (int i=1;i<=n;++i)
	  for (int j=1;j<=n;++j) e[i][j]=2;
  }
  
  bool Ins(int x,int y,int v){
	if (v==2) return 1;
	++x;++y;
	if (e[x][y]==2) {e[x][y]=e[y][x]=v;return 1;}
	return e[x][y]==v;
  }
  
  int uni[N+9];
  
  int Query_uni(int k){return k==uni[k]?k:uni[k]=Query_uni(uni[k]);}
  
  int deg[N+9];
  
  int Get_ans(){
	for (int i=1;i<=n;++i) uni[i]=i,deg[i]=0;
	int cnt=0;
	for (int i=1;i<=n;++i)
	  for (int j=i+1;j<=n;++j){
		if (e[i][j]==2) ++cnt;
	    else deg[i]+=e[i][j],deg[j]+=e[i][j];
	  }
	if (n&1){
	  for (int i=1;i<=n;++i)
	    for (int j=i+1;j<=n;++j){
		  if (e[i][j]<2) continue;
		  int fx=Query_uni(i),fy=Query_uni(j);
		  if (fx==fy) continue;
		  uni[fy]=fx;deg[fx]+=deg[fy];--cnt;
		}
	  for (int i=1;i<=n;++i)
		if (Query_uni(i)==i&&deg[i]&1) return 0;
	}
	int res=1;
	for (int i=1;i<=cnt;++i) smul(res,2);
	return res;
  }
  
}g[2];

int ans;

void Get_ans(){
  g[0].Get_n(n+2>>1);
  g[1].Get_n(n+1>>1);
  for (int i=1;i<n;++i)
	for (int j=1;j<n;++j){
	  int x=min(i+j,n-i+n-j),y=max(j-i,i-j),v=s[i][j]=='x'?0:1+(s[i][j]=='?');
	  if (!g[i+j&1].Ins(x>>1,y>>1,v)) return;
	}
  ans=mul(g[0].Get_ans(),g[1].Get_ans());
}

void work(){
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 14812
#include<iostream>
using namespace std;
const int MAX = 105;
char map[MAX][MAX];
bool visit[MAX][MAX];
int h, w;
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
void bfs(int x, int y)
{
	visit[x][y] = true;
	int xx, yy;
	for (int i = 0; i < 4; i++)
	{
		xx = x + dx[i];
		yy = y + dy[i];
		if (xx >= 0 && xx < h&&yy >= 0 && yy < w)
		{
			if (map[x][y] == map[xx][yy] && !visit[xx][yy])
			{
				bfs(xx, yy);
			}
		}
	}
}
int main()
{
	int i, j;
	while (cin >> h >> w)
	{
		if (h == 0 && w == 0)
		{
			break;
		}
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				cin >> map[i][j];
				visit[i][j] = false;
			}
		}
		int sum = 0;
		for (i = 0; i < h; i++)
		{
			for (j = 0; j < w; j++)
			{
				if (!visit[i][j])
				{
					bfs(i, j);
					sum++;
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <ctype.h>
using namespace std;

typedef long long ll;

int dx[4] = { 0, -1, 1, 0 };
int dy[4] = { -1, 0, 0, 1 };

int main() {
  int n;
  cin >> n;
  int maxval = 0;
  int minval = 1e9 + 1;
  int tmp;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    maxval = max(maxval, tmp);
    minval = min(minval, tmp);
  }

  cout << maxval - minval << endl;
  return 0;
}


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

bool psort(pair<ll,pair<ll,ll> > a,pair<ll,pair<ll,ll> > b){
    return a.second.first<b.second.first;
}

int main(){

    ll n;
    cin >> n;

    vector<pair<ll,pair<ll,ll> > > x(n);

    rep(i,n){
        cin >> x[i].first;
        x[i].second.first=i;
    }
    sort(x.begin(),x.end());
    rep(i,n){
        x[i].second.second=i;
    }
    ll t1=x[n/2].first;
    ll t2=x[n/2-1].first;
    sort(x.begin(),x.end(),psort);

    rep(i,n){
        if(x[i].second.second<n/2){
            cout << t1 << endl;
        }else{
            cout << t2 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		int[] b = new int[n];
		int k = Integer.MIN_VALUE;
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
			k = Math.max(k, a[i]);
		}
		countingSort(a, b, k);
		StringBuilder sb = new StringBuilder();
		sb.append(b[0]);
		for (int i = 1; i < n; i++) {
			sb.append(" " + b[i]);
		}
		System.out.println(sb.toString());
	}

	private static void countingSort(int[] a, int[] b, int k) {
		int[] c = new int[k + 1];
		for (int i = 0; i < a.length; i++) {
			c[a[i]]++;
		}
		for (int i = 1; i <= k; i++) {
			c[i] += c[i - 1];
		}
		for (int i = a.length - 1; i >= 0; i--) {
			c[a[i]]--;
			b[c[a[i]]] = a[i];
		}
	}
}



Measured memory_bytes: 198460
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 2e9;
typedef pair<int, int> pi;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    if (n >= 30)cout << "Yes";
    else cout << "No" << "\n";
}


Measured memory_bytes: 3648
/******************************************
* AUTHOR : AAYUSH GARG*
* NICK : aayushgarg_03 *
* INSTITUTION : BIT MESRA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define mod 1000000007
#define dd double
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define VP vector< pii >
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define ascii(c) (int)char (c)
#define all(v) (v).begin(),(v).end()
#define Sort(v) sort(v.begin(), v.end(), sortbysec)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
#define N 1000000
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(a,max3(b,c,d))
#define min4(a,b,c,d) min(a,min3(b,c,d))

ll prime[N];

ll mulmod(ll a, ll b, ll m) 
{ 
    ll res = 0;  
    a = a % m; 
    while (b > 0) 
    { 
        if (b % 2 == 1) 
            res = (res + a) % m; 

        a = (a * 2) % m; 
        b /= 2; 
    } 
  
    return res % m; 
} 

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;     
  
    x = x % p;  
  
    while (y > 0) 
    {    
      if (y & 1) 
            res = (res*x) % p; 
    
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
}

void sieve() {
    for(ll i = 0;i < N;i++)
        prime[i] = 1;
    prime[0] = 0;
    prime[1] = 0;
    for(ll i = 2;i*i < N;i++) {
        if(prime[i] == 0)
            continue;
        for(ll j = i*i;j < N;j+=i) {
            prime[j] = 0;
        }
    }
    for(ll i = 1;i < N;i++)
        prime[i] += prime[i-1];
}



bool sortbysec(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

/*vec v;
void divisors(ll n)
{
    
for(ll i=1;i<=sqrt(n);i++)
{
    if(n%i==0)
    {
        if(i==n/i)
        v.pb(i);
        else
        {
            v.pb(i);
            v.pb(n/i);
        }
        
    }
}

sort(all(v));
}*/




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

//ll t; cin>>t; while(t--){}
string s,t;
cin>>s>>t;

ll m = s.length();
ll n = t.length();

ll dp[m+1][n+1];

f(i,0,m+1)
{
    f(j,0,n+1)
    {
        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]);
    }
}

ll len = dp[m][n];

//cout<<len<<endl;

string ans = "";

ll i = m;
ll j = n;

while(i > 0 && j > 0)
{
    if(s[i-1] == t[j-1] )
    {
        ans += s[i-1];
        i--;
        j--;
        
    }

    else if(dp[i-1][j] > dp[i][j-1])
    i--;
    else
    j--;
}

reverse(all(ans));

cout<<ans<<endl;



return 0;
}


Measured memory_bytes: 70656
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

LLI getAns(LLI a,LLI b) {
    if ((a == 0) || (b == 0)) return 0;
    else if (a == b) return a;
    if (a > b) swap(a,b);
    return 2*a*((b-1)/a)+getAns(a,b-((b-1)/a)*a);
}
int main() {
    LLI N,X;
    cin >> N >> X;
    cout << getAns(X,N-X)+N << endl;

    return 0;
}



Measured memory_bytes: 256
S = input().split(" ")
K = int(S[0])
N = int(S[1])
ARR = [int(s) for s in input().split(" ")]


def calculate(k,n,arr):
    result = []
    for i in range(n-1):
        s = arr[i+1] - arr[i]
        m = k - s
        result.append(m)

    result.append(arr[n-1] - arr[0])

    print(min(result))


calculate(K,N,ARR)


Measured memory_bytes: 24860
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int s=0;char ch=getchar();
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) s=s*10+ch-'0',ch=getchar();
	return s;
} 
const int N=1e5+5;
typedef long long ll;
ll base=1e18,mod=998244353;
int n;
ll pw[N*3];
vector<int> G[N];
int sg[4][N],mx[4];
int f[4][N];
inline void add(int &x,int y){
	x+=y;if(x>=mod) x-=mod; 
}
int main(){
	n=read();
	pw[0]=1;base%=mod;
	for(int i=1;i<=3*n;i++)  pw[i]=pw[i-1]*base%mod;
	for(int T=1;T<=3;T++){
		int m=read();
		for(int i=1;i<=n;i++) G[i].clear();
		for(int i=1;i<=m;i++){
			int u=read(),v=read();
			if(u>v) swap(u,v);
			G[u].push_back(v);
		}
		set<int> s;
		for(int i=n;i>=1;i--){
			s.clear();
			for(int j:G[i]) s.insert(sg[T][j]);
			while(s.find(sg[T][i])!=s.end()) sg[T][i]++;
			mx[T]=max(mx[T],sg[T][i]);
		}
		for(int i=1;i<=n;i++) add(f[T][sg[T][i]],pw[i]);
	}
	int ans=0;
	for(int i=0;i<=mx[1];i++)
		for(int j=0;j<=mx[2];j++)
			add(ans,1ll*f[1][i]*f[2][j]%mod*f[3][i^j]%mod);
	printf("%d",ans);
	return 0;
}

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

//mod
const int mod = 1e9 + 7;
int powmod(int x, int y) { //x^y
	int rv = 1;
	for (; y > 0; y >>= 1, x = (long long) x * x % mod)
		if (y & 1)
			rv = (long long) rv * x % mod;
	return rv;
}

int n;
ll ans;

int main() {
	cin >> n;
	ans = powmod(10, n);
	ans -= powmod(9, n) * 2;
	ans += powmod(8, n);
	ans %= mod;
	if (ans < 0)
		ans += mod;
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define double long double
#define int long long
#define mii map<int,int>
#define pii pair<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define inf 10000000000000000 //10^16
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define bisea binary_search
#define cend cout<<endl;
#define F first
#define S second
using namespace std;
signed main() {
	int n,sum=0,MIN=inf;
	cin>>n;
	int a[n];
	rep(i,n) {
		cin>>a[i];
		sum+=a[i];
	}
	int cnt=0;
	rep(i,n-1) {
		cnt+=a[i];
		sum-=a[i];
		MIN=min(MIN,abs(cnt-sum));
	}
	cout<<MIN<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int maxn = 1e5 + 10;

int N, L;
int a[maxn];

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

    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> N >> L;
    for (int i = 1; i <= N; ++i) cin >> a[i];

    int idx = -1;
    for (int i = 1; i < N; ++i) if (a[i] + a[i + 1] >= L) {
        idx = i;
        break;
    }
    if (idx == -1) {
        cout << "Impossible\n";
        return 0;
    }
    cout << "Possible\n";
    for (int i = 1; i < idx; ++i) cout << i << "\n";
    for (int i = N - 1; i >= idx; --i) cout << i << "\n";

    return 0;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int score = 0;
  int maxscore =0;
  
  for (int i=0;i<n;i++){
    if(s.at(i) == 'I'){
      score++;
    }
    else{
      score--;
    }
    maxscore = max(score,maxscore);
  }
  cout << maxscore << endl;
}

Measured memory_bytes: 256
#include<iostream>
#define rep(i, n) for (int i = 0; i < (n); i ++)
using namespace std;

int main()
{
  int max = 0;
  int min = 200005;
  int n;
  cin >> n;
  int count = 0;
  int tmp;
  rep(i, n)
  {
    cin >> tmp;
    if (tmp < min)
    {
      min = tmp;
      count ++;
    }
  }
  
  cout << count;
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    var ans = 0
    for (i in s.indices) {
        val j = s.length - i - 1
        if (i >= j) {
            break
        }
        if (s[i] != s[j]) {
            ans++
        }
    }
    println(ans)
}

Measured memory_bytes: 31140
#include<iostream>

long long a[5],min=1000000000000001,p,res;

int main(){

    std::cin>>p;

    for(int i=0;i<5;i++){
    std::cin>>a[i];
    if(min>a[i])
    min=a[i];
    }

    if(p%min!=0)
    res++;

    res+=p/min;

    std::cout<<4+res<<std::endl;

    return 0;
}

Measured memory_bytes: 256
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8')

const [a, b, c, d] = stdin.split('\n')[0].split(' ').map(Number)

const res = x => {
  const l = a + b
  const r = c + d

  if(l === r){
    return 'Balanced'
  } else if ( l < r){
    return 'Right'
  } else {
    return 'Left'
  }
}

console.log(res())

Measured memory_bytes: 9420
#include<cstdio>
const int MAXN=200005,MAXA=2005,ZERO=2005,MOD=1000000007;

int powmod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=(1LL*ret*a)%MOD;
		a=(1LL*a*a)%MOD;
		b>>=1;
	}
	return ret;
}

int a[MAXN],b[MAXN];
int f[MAXA*2][MAXA*2];
int fac[MAXA*4],ifac[MAXA*4];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		f[ZERO-a[i]][ZERO-b[i]]++;
	}
	for(int i=1;i<MAXA*2;i++)
		for(int j=1;j<MAXA*2;j++)
			f[i][j]=((f[i][j]+f[i-1][j])%MOD+f[i][j-1])%MOD;
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=(ans+f[a[i]+ZERO][b[i]+ZERO])%MOD;
	fac[0]=1;
	for(int i=1;i<MAXA*4;i++)
		fac[i]=(1LL*fac[i-1]*i)%MOD;
	ifac[MAXA*4-1]=powmod(fac[MAXA*4-1],MOD-2);
	for(int i=MAXA*4-2;i>=0;i--)
		ifac[i]=(1LL*ifac[i+1]*(i+1))%MOD;
	
	for(int i=1;i<=n;i++)
		ans=(ans-1LL*fac[(a[i]+b[i])*2]*ifac[b[i]*2]%MOD*ifac[a[i]*2]%MOD)%MOD;
	ans=(ans+MOD)%MOD;
	ans=(1LL*(MOD+1)/2*ans)%MOD;
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 64640
# A=gets.to_i
# B=gets.split.map(&:to_i)
# C=N.times.map{gets.to_i}
# D=N.times.map{gets.split.map(&:to_i)}
# S=gets.chomp
# MOD=1000000007


A=gets.chomp

if A[0]==A[1] || A[1]==A[2] || A[2]==A[3]
  puts "Bad"
else
  puts "Good"
end 

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

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if(s == u) cout << a-1 << " " << b;
  else if (t == u) cout << a << " " << b-1;
  return 0;
}


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

using namespace std;

#define INIT 9999999
int main()
{
    int n, m, x;
    int c[12], a[12][12];
    
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    int mmin = INIT;
    int upper = (int)pow(2, n);
    for (int i = 0; i < upper; i++) {
        int cost = 0;
        int level[12] = {0};
        for (int j = 0; j < n; j++) {
            if ( ((i >> j) & 0x01) != 0) {
                cost += c[j];
                for (int k = 0; k < m; k++) {
                    level[k] += a[j][k];
                }
            }
        }
        bool flag = true;
        for (int j = 0; j < m; j++) {
            if (level[j] < x) {
                flag = false;
                break;
            }
        }
        if (flag) {
            mmin = mmin < cost ? mmin : cost;
        }
    }
    if (INIT == mmin) {
        cout << -1 << endl;
    } else {
        cout << mmin << endl;
    }
    return 0;
}


Measured memory_bytes: 4096
while True:
    try:
        As,Bs = map(int,input().split())
        a,b = As, Bs
        while True:
            if a % b == 0:
                gcd = b
                break
            a,b = b, a % b
        print(gcd,int(As * Bs / gcd))
    except EOFError:
        break

Measured memory_bytes: 7484
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;


int main() {
  int n;cin >> n;
  vector<int> ans(n+1,0);
  for (int i = 1; i <= 100; ++i){
    for (int j = 1; j <= 100; ++j){
      for (int k = 1; k <= 100; ++k){
        int v = i*i+j*j+k*k+i*j+j*k+k*i;
        if(v<=n) ans[v]++;
      }
    }
  }
  rep(i,n){
    cout << ans[i+1] << endl;
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, a, max = 0, ans = 0;
  cin >> n;
  map<ll, ll, greater<ll>> mp;
  rep(i, n) {
    cin >> a;
    mp[a]++;
  }

  for (auto x : mp) {
    if (x.second >= 2 && x.second < 4) {
      if (max == 0) {
        max = x.first;
      } else {
        ans = x.first * max;
        break;
      }
    } else if (x.second >= 4) {
      if (max == 0) {
        ans = x.first * x.first;
        break;
      } else {
        ans = x.first * max;
        break;
      }
    }
  }
  cout << (ans!=0 ? ans : 0) << endl;
  return 0;
}


Measured memory_bytes: 6528
def main():
    mod, pow3, pow3i, p = 2**61-1, [1]*400001, [1]*200001, 1
    i3 = pow(3, mod-2, mod)
    for i in range(1, 400001):
        pow3[i] = p = p*3 % mod
    p = 1
    for i in range(1, 200001):
        pow3i[i] = p = p*i3 % mod

    class rolling_hash():
        def __init__(self, seq, char_list=None):
            seq_size = self.seq_size = len(seq)  # 文字列の長さ
            mod = self.mod = 2**61-1  # mod
            Hash = self.Hash = [0]*(seq_size+1)  # 先頭からi-1文字目までのハッシュ値
            for i in range(seq_size):
                Hash[i+1] = (Hash[i] + (seq[i]+1) * pow3[i]) % mod

        def calc_hash(self, l, r):  # l文字目からr-1文字目までのハッシュ値
            return ((self.Hash[r]-self.Hash[l])*pow3i[l] % self.mod)

    n = int(input())
    a, b = list(map(int, input().split())), list(map(int, input().split()))
    memo = []

    a1 = rolling_hash([a[i-1] ^ a[i] for i in range(n)] +
                      [a[i-1] ^ a[i] for i in range(n)])
    b_hash = rolling_hash([b[i-1] ^ b[i] for i in range(n)]).calc_hash(0, n)
    for i in range(n):
        if a1.calc_hash(i, i+n) == b_hash:
            memo.append(i)
    b0 = b[0]
    for i in memo:
        x = b0 ^ a[i]
        print(i, x)


main()


Measured memory_bytes: 81448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for (int i = 0; i < tx - sx; i++) cout << 'R';
  for (int i = 0; i < ty - sy; i++) cout << 'U';
  for (int i = 0; i < tx - sx; i++) cout << 'L';
  for (int i = 0; i < ty - sy; i++) cout << 'D';
  cout << 'D';
  for (int i = 0; i <= tx - sx; i++) cout << 'R';
  for (int i = 0; i <= ty - sy; i++) cout << 'U';
  cout << "LU";
  for (int i = 0; i <= tx - sx; i++) cout << 'L';
  for (int i = 0; i <= ty - sy; i++) cout << 'D';
  cout << "R\n";
  return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, M;
  cin >> N >> M;
  vector<vector<vector<ll>>> path(N);
  for (ll i = 0; i < M; ++i) {
    ll l, r, c;
    cin >> l >> r >> c;
    path.at(l - 1).push_back({r - 1, c});
  }
  multiset<ll> st;//min
  vector<vector<ll>> imos(N + 1);
  st.insert(0);
  imos.at(1).push_back(0);
  for (ll i = 0; i < N; ++i) {
    for (ll j = 0; j < imos.at(i).size(); ++j) {
      st.erase(st.lower_bound(imos.at(i).at(j)));
    }
    if (st.size() == 0) {
      cout << "-1" << "\n";
      return 0;
    }
    ll m = *st.begin();
    for (ll j = 0; j < path.at(i).size(); ++j) {
      ll cost = m + path.at(i).at(j).at(1);
      st.insert(cost);
      imos.at(path.at(i).at(j).at(0) + 1).push_back(cost);
    }
  }
  // for (ll i = 0; i < N + 1; ++i) {
  //   cout << "i" << i << "\n";
  //   for (ll j = 0; j < imos.at(i).size(); ++j) {
  //     cout << imos.at(i).at(j) << " ";
  //   }
  //   cout << "\n";
  // }
  cout << *st.begin() << "\n";
}


Measured memory_bytes: 17652
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 

int dp[100][2];

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


int n;
cin>>n;
vector<int>v(n);


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

sort(v.begin(),v.end());
int ans=0;

for(int i=0;i<n;i++)
{
  for(int j=i+1;j<n;j++)
  {
       int x=v[i]+v[j];
       auto it = lower_bound(v.begin(),v.end(),x);
       int k=distance(it,v.end());
       ans+=n-j-1-k;
  }
}
   cout<<ans<<"\n";

}

    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb(x)  push_back(x);
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

int main() {
    int N;
    cin >> N;
    vi W(N);
    int total = 0;
    rep(i,N) {
        cin >> W.at(i);
        total += W.at(i);
    }
    int S1 = 0;
    int ans = 1000000;
    rep(i,N) {
        S1 += W.at(i);
        ans = min(ans, abs(S1 + S1 - total));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
using namespace std;
int main(void) {
    double a, b, c, d, e, f;
    while(cin >> a >> b >> c >> d >> e >> f){
        double x = (f - (c*e/b)) / (d - ((a*e)/b));
        if(x == 0){
            x = 0;
        }
        double y = (c/b) - (a/b) * x;

        cout << fixed;
        cout << setprecision(3) << x << ' ' << y << endl;
    }
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    for (int i = m / n; i >= 1; i--)
    {
        if (m % i == 0)
        {
            int t = m / i;
            if (t >= n)
            {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
import sys
import re
import math
import collections
import decimal
import bisect
import itertools

import copy

# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n, k = ns()
    a = na()

    total = 0
    for i in range(n):
        for j in range(n):
            if a[i] < a[j]:
                total += 1
                total %= MOD

    ans = total * (k * (k - 1) // 2) % MOD

    cnt = 0
    for i in range(n):
        for j in range(i):
            if a[j] > a[i]:
                cnt += 1
                cnt %= MOD
    cnt = cnt * k % MOD

    res = (ans + cnt) % MOD

    print(res)


if __name__ == '__main__':
    main()


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

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

    int m,d;
    cin >> m >> d;

    int res = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= d; j++){
            int d1 = j % 10;
            int d10 = j / 10;
            if(j >= 10 && d10 >= 2 && d1 >= 2){
                if(d1 * d10 == i) res++;
            }
        }
    }
    cout << res << endl;
}




Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<lint> a(n);
    REP(i, n){
        cin >> a[i];
    }
    p_que pq;
    REP(i, n){
        pq.push(a[i]);
    }
    REP(i, m){
        auto t = pq.top();
        pq.pop();
        t /= 2;
        pq.push(t);
    }
    lint ans = 0;
    while(!pq.empty()){
        auto t = pq.top();
        pq.pop();
        ans += t;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

ll mod_pow(ll x, ll n)
{
    x%=mod;
    n%=(mod-1);

    ll pw[32];
    pw[0]=x;
    for(int i=1; i<32; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;

    ll ret=1;
    rep(i,32)if(n>>i&1) (ret*=pw[i])%=mod;
    return ret;
}

ll mod_inv(ll x)
{
    return mod_pow(x,mod-2);
}

ll C(ll D, ll P)
{
    ll x=1,y=1;
    for(ll i=1; i<=P; ++i)
    {
        (y*=i)%=mod;
        (x*=(D-P+i)%mod)%=mod;
    }

    return (x*mod_inv(y))%mod;
}

ll dp[2001][2001];

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

    int N,X;
    ll D;
    while(cin >>N >>D >>X,N)
    {
        if(X==1)
        {
            cout << "0" << '\n';
            continue;
        }

        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=1; i<=N; ++i)
        {
            ll sum=0;
            for(int j=1; j<=N; ++j)
            {
                sum = (sum+dp[i-1][j-1])%mod;
                dp[i][j]=sum;
                if(j-X+1>=0) sum = (sum - dp[i-1][j-X+1] + mod)%mod;
            }
        }

        ll ans=0;

        for(int i=1; i<=N; ++i)
        {
            if(D-i<0) break;
            (ans += (dp[i][N]*C(D,i))%mod)%=mod;
        }

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

Measured memory_bytes: 34372
package main

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

func main() {
	c := make([][]int, 3)
	for i := range c {
		c[i] = append(c[i], readInt())
		c[i] = append(c[i], readInt())
		c[i] = append(c[i], readInt())
	}

	for b1 := 0; b1 <= 100; b1++ {
		a := []int{c[0][0] - b1, c[1][0] - b1, c[2][0] - b1}
		b := []int{b1, c[0][1] - a[0], c[0][2] - a[0]}
		// fmt.Println(a, b)

		ok := true
	label:
		for i := range c {
			for j := range c[i] {
				if c[i][j] != a[i]+b[j] {
					ok = false
					break label
				}
			}
		}
		if ok {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
(defun solver ()
  (let* ((n (read)) (si (make-array n :fill-pointer 0))
         (temp 0) (maxcounter 0) word)
      (loop repeat n do
            (vector-push (read) si))
      (let* ((m (read)) (ti (make-array m :fill-pointer 0)))
        (loop repeat m do
              (vector-push (read) ti))
        (loop for i from 0 below n do
              (setf word (aref si i))
              (loop for j from 0 below n do
                    (if (equal word (aref si j))
                        (incf temp)))
              (loop for j from 0 below m do
                    (if (equal word (aref ti j))
                        (decf temp)))
              (when (> temp maxcounter) (setf maxcounter temp))
              (setf temp 0))
        (format t "~a~%" maxcounter))))

(solver)

Measured memory_bytes: 16488
#include <stdio.h>
int main()
{
    int countryX,countryY,N,M;
    int x[100],y[100];
    int i=0,j,count=0;
    scanf("%d %d %d %d",&N,&M,&countryX,&countryY);

    while(i!=N){
        scanf("%d",&x[i]);
        i++;
    }

    i=0;

    while(i!=M){
        scanf("%d",&y[i]);
        i++;
    }    

    if(countryY - countryX <= 0){
        count++;
    }

    for(i=0;i<N;i++){
        for(j=0;j<M;j++){
            if(y[j] - x[i] <= 0){
                count++;
            }
            if(y[j]<=countryX){
                count++;
            }
            if(x[i]>=countryY){
                count++;
            }
        }
    }

    if(count == 0){
        printf("No War");
    }else{
        printf("War");
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define max(x, y) (((x) > (y)) ? (x) : (y))

int solv(int n) {
  int i, res = 0, abc[100000][3];

  for (i = 0; i < n; i++) {
    scanf("%d %d %d", &abc[i][0], &abc[i][1], &abc[i][2]);
  }

  for (i = 1; i < n; i++) {
    abc[i][0] = max(abc[i - 1][1] + abc[i][0], abc[i - 1][2] + abc[i][0]);
    abc[i][1] = max(abc[i - 1][0] + abc[i][1], abc[i - 1][2] + abc[i][1]);
    abc[i][2] = max(abc[i - 1][0] + abc[i][2], abc[i - 1][1] + abc[i][2]);
  }

  for (i = 0; i < 3; i++) {
    res = max(res, abc[n - 1][i]);
  }

  return res;
}

int main(int argc, char **argv) {
  int n;

  while (scanf("%d", &n) != EOF) {
    printf("%d\n", solv(n));
  }

  return 0;
}


Measured memory_bytes: 1280