akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
using namespace std;
const int N=1010;
int main()
{
    queue<int> q[N];
    int n,T;
    cin>>n>>T;
    while(T--)
    {
        int c;
        cin>>c;
        if(c==0)
        {
            int t,x;
            cin>>t>>x;
            q[t].push(x);
        }else if(c==1)
        {
            int t;
            cin>>t;
            if(q[t].size())
            cout<<q[t].front()<<endl;
        }else
        {
            int t;
            cin>>t;
            if(q[t].size())
            q[t].pop();
        }
    }
}


Measured memory_bytes: 4276
from collections import Counter
cnt = Counter()
for i in range(3):
  cnt.update([int(item) for item in input().split()])
a = list(cnt.values())
a.sort()
if a[0] == 1 and a[1] == 1 and a[2] == 2 and a[3] == 2:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3316
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String s = scan.next();
		String t = scan.next();
		String x = t.substring(0,t.length()-1);
		
		if(s.equals(x)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}	
	
	
	//最小公約数
	/*
	static int gcd (int a, int b) {
		int temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	*/
	
	//入れ替え
	/*
	static int swap (int a, int b) {
		int swap_arr[] = new int[2];
		
		swap[0] = b;
		swap[1] = a;
		
		return swap_arr;
	}
	*/
	
}



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

int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  double ans = 0;
  for (int i = 1; i <= N; ++i) {
    long long score = i;
    int x = 0;
    while (score < K)
      score *= 2, ++x;
    int sum = N;
    for (int j = 0; j < x; ++j)
      sum *= 2;
    ans += 1. / sum;
  }
  printf("%.9f\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;

    int ans = 3 * pow(N, 2.0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

long long int n, a, b;
long long int MOD = 1000000007;

long long int POW(long long int a, long long int k) {
	if (k == 0) { return 1; }
	else if (k == 1) { return a; }

	if (k % 2 == 1) { return (POW(a, k - 1)*a) % MOD; }

	long long int tmp = POW(a, k / 2);

	return (tmp*tmp) % MOD;
}

long long int INV(long long int a) {
	return POW(a, MOD - 2);
}
long long int P[200005];

int main(void) {
	cin >> n >> a >> b;

	P[0] = 1;
	for (int i = 1; i <= 200002; i++) {
		P[i] = (P[i - 1] * i) % MOD;
	}
/*
	long long int val = 1;

	long long int tmp;
	for (long long int i = 2; i <= n * 2; i++) {
		val *= i;
		val %= MOD;
		if (i == n) { tmp = val; }
	}

	long long int tmp2 = INV(tmp);
	val = (val*tmp2) % MOD;
	val = (val*tmp2) % MOD;

	long long int ans;
	ans = (val - 1 + MOD) % MOD;

	long long int wa = 1;
	for (long long int i = n; i <= a+n-1; i++) {
		wa *= i;
		wa %= MOD;
	}

	wa = (wa*INV(P[a])) % MOD;

	ans = (ans - wa + MOD) % MOD;

	long long int wb = 1;
	for (long long int i = n; i <= b + n - 1; i++) {
		wb *= i;
		wb %= MOD;
	}

	wb = (wb*INV(P[b])) % MOD;

	ans = (ans - wb + MOD) % MOD;

	cout << ans << endl;
	*/


	long long int ans = POW(2, n);

	//cout << ans << endl;

	ans = (ans - 1 + MOD) % MOD;

//	cout << ans << endl;

	long long int wa = 1;
	for (long long int i = n; i >= n - a + 1; i--) {

		wa *= i;
		wa %= MOD;
	}

	wa = (wa*INV(P[a])) % MOD;

//	cout << "wa= " << wa << endl;

	ans = (ans - wa + MOD) % MOD;

	long long int wb = 1;
	for (long long int i = n; i >= n - b + 1; i--) {

		wb *= i;
		wb %= MOD;
	}

	wb = (wb*INV(P[b])) % MOD;

//	cout << "wb= " << wb << endl;

	ans = (ans - wb + MOD) % MOD;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define li long int
#define ll long long int
#define vec(x) vector<x> 
#define st(x) set<x> 
#define mpp(x,y) map<x,y>
#define qq(x) queue<x>
#define pqq(x) priority_queue<x> 
#define search(x,y,z) binary_search(x,y,z)
#define pi(x,y) pair<x,y>
#define forf(i,x,y) for(ll i=x;i<y;i++)
#define forl(i,x,y) for(ll i=x-1;i>=y;i--)
#define rev(x) reverse(x.begin(),x.end())
#define mem(x,a) memset(x,a,sizeof(x))
#define mod 1000000007
#define nxt_per(x) next_permutation(x.begin(),x.end())
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define pp push
#define po pop
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define vp(x,y) vec(pi(x,y) )
#define vv(x) vector<vector<x> >
#define all(x) x.begin(),x.end()
/*
void check(int x,int y)
{
	//all 8 directions
	if(x-1<n && y-1<m)
	if(x-1<n && y<m)
	if(x-1<n && y+1<m)
	if(x<n && y-1<m)
	if(x<n && y+1<m)
	if(x+1<n && y-1<m)
	if(x+1<n && y<m)
	if(x+1<n && y+1<m)
}
*/
/*
unordered_map<ll,ll> um
um.reserve(1<<15);
um.max_load_factor(0.25);
*/

using namespace std;

int main()
{
	fastio;
// best of luck don't loose hope man	

	string s;
	cin>>s;
	if(s.size()==2)
		cout<<s;
	else
	{	reverse(all(s));
		cout<<s;
	}
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int t[100];
    int sum = 0;
    for(int i = 0; i < n; i++){
        cin >> t[i];
        sum += t[i];
    }
    int m;
    cin >> m;
    int p[100], x[100];
    for(int i = 0; i < m; i++){
        cin >> p[i] >> x[i];
        cout << sum - t[p[i] - 1] + x[i] << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a - c) <= d or (abs(b - c) <= d and abs(a - b) <= d)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
def main():
    n = int(input())
    As = list(map(int, input().split()))
    ans = float("inf")

    for i in range(-100, 101):
        ans_temp = 0
        for j in range(n):
            ans_temp += (As[j] + i)**2
        ans = min(ans, ans_temp)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9136
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll N,K;
	cin>>N>>K;
	vector<ll> A(N),F(N);
	REP(i,N){
		cin>>A[i];
	}
	REP(i,N){
		cin>>F[i];
	}
	sort(A.begin(),A.end());
	sort(F.rbegin(),F.rend());
	//二分探索
	ll l=-1,r=1e12;
	while((l+1)<r){
		ll m=(l+r)/2;
		ll s=0;
		REP(i,N) s+=max(A[i]-m/F[i],0ll);
		if(s<=K) r=m;
		else l=m;
	}
	cout<<r;
	return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scan = new Scanner(System.in);
    String a = scan.nextLine();
    String b = scan.nextLine();
    scan.close();

    System.out.println(LCS(a, b));
  }

  private static String LCS(String a, String b) {
    if (a.length() == 0 || b.length() == 0)
      return "";
    int[][] dp = new int[a.length() + 1][b.length() + 1];

    for (int i = 0; i < dp.length; i++)
      dp[i][0] = i;

    for (int j = 0; j < dp[0].length; j++)
      dp[0][j] = j;

    for (int i = 1; i < dp.length; i++)
    for (int j = 1; j < dp[0].length; j++) {
      if (a.charAt(i - 1) == b.charAt(j - 1)) {
        dp[i][j] = dp[i-1][j-1];
      } else {
        dp[i][j] = Math.min(dp[i][j-1], dp[i-1][j]) + 1;
      }
    }

    
    //for (int[] aa : dp)
      //System.out.println(Arrays.toString(aa));
         
    StringBuilder sb = new StringBuilder();

    int i = dp.length - 1;
    int j = dp[0].length - 1;

    while (i >= 0 && j >= 0) {
      int strI = i - 1;
      int strJ = j - 1;
      if (strI >= 0 && strJ >= 0 && a.charAt(strI) == b.charAt(strJ)) {
        //System.out.println("Diagonal at " + i + " " + j);
        sb.append(a.charAt(strI));
        i--;
        j--;
      } else {
        int top = i > 0 ? dp[i - 1][j] : Integer.MAX_VALUE;
        int left  = j > 0 ? dp[i][j - 1] : Integer.MAX_VALUE;
        //System.out.println("top " + top + " left " + left);
        if (left > top) {
          //System.out.println("i-- " + i + " " + j);
          i--;
        }
        else {
          //System.out.println("j-- " + i + " " + j);
          j--;
        }
      }
    }
    return sb.reverse().toString();
  }

}

Measured memory_bytes: 81180
a = [int(input()) for _ in range(5)]
b = []
ans = 0
for i in range(5):
    if a[i] % 10 == 0:
        ans += a[i]
    else:
        b.append([a[i], a[i] % 10])
sorted_b = sorted(b, key=lambda x: x[1], reverse=True)

for i in range(len(sorted_b)):
    if i == len(sorted_b) - 1:
        ans += sorted_b[i][0]
    else:
        ans += sorted_b[i][0] + (10 - sorted_b[i][1])
print(ans)

Measured memory_bytes: 3064
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    let mut v2 = Vec::new();
    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
        let v = s.trim().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect();
        v2.push(v);
    }
    v2
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


fn main() {
    let stdin = read_vec::<isize>();
    let (f, s) = (stdin[0], stdin[1]);
    let result = vec![f + s, f - s, f * s].into_iter().max();
    println!("{:?}", result.unwrap());
}

Measured memory_bytes: 4352
#include<cstdio>
using namespace std;
const int INF = 1e9;

int n, k, w[100000];
int w_mx = 0;

bool b_search(int p)
{
  int pointer = 0;
  for(int i = 0; i < k && pointer < n; i++){
    int truck = 0;
    while(pointer < n && truck + w[pointer] <= p)
      truck += w[pointer++];
  }
  
  if(pointer < n)
    return false;
  return true;
}

int main()
{
  scanf("%d%d", &n, &k);
  for(int i = 0; i < n; i++)
    scanf("%d", &w[i]);

  int s = 0, e = INF;
  while(e - s > 1){
    int mid = (s + e) / 2;
    if(b_search(mid))
      e = mid;
    else
      s = mid;
  }

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

Measured memory_bytes: 1412
using System;
public class Hello{
    public static void Main(){
      int a=int.Parse(Console.ReadLine());
      int b=int.Parse(Console.ReadLine());
      int c=int.Parse(Console.ReadLine());
      int x=int.Parse(Console.ReadLine());
      int ans=0;
      for(int i=0;i<=a;i++){
       for(int j=0;j<=b;j++){
        for(int k=0;k<=c;k++){
         if(500*i+100*j+50*k==x)ans++; 
        }
       }
      }
      Console.WriteLine(ans);
    }
}

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

using namespace std;


int main() {
    int N,M; cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<vector<int>> Yd(N+1, vector<int>());

    for(int i=0;i<M;i++) {
        cin >> P[i] >> Y[i];
        Yd[P[i]].push_back(Y[i]);
    }

    for(int i=0;i<N;i++) {
        sort(Yd[i+1].begin(), Yd[i+1].end());
    }

    for(int i=0;i<M;i++) {
        ostringstream sp, sn;
        sp << setw(6) << setfill('0') << P[i];
        sn << setw(6) << setfill('0') << int(lower_bound(Yd[P[i]].begin(), Yd[P[i]].end(), Y[i]) - Yd[P[i]].begin()) + 1;
        
        cout << sp.str() << sn.str() << endl;
    }
    return 0;
}


Measured memory_bytes: 7808
import fractions
N, M = map(int, input().split())

k = M // N + 1
ans = 1
for i in reversed(range(1, k+1)):
    if ans > i:
        break
    tmp = max(M - (N-1)*i, 1)
    if tmp % i == 0:
        ans = max(ans, i)

print(ans)


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

string a, b;
int n;

bool perfectSquare(int n){
	double s = sqrt(n);
	return (s-floor(s)) == 0;
}

int main() {
	cin >> a >> b;
	a += b;
	n = stoi(a);
	if(perfectSquare(n)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define YN(y, n, b) (b? y : n)
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    cout << (i32)pow(N, 3) << endl;
}


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

using namespace std;

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b,&c);
	if(a==b || b==c || c==a){
		if(!(a==b && b==c)){
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 256
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()

n = readInt()
a = readInts()
s = 0
for i in a:
	s = s^i

for i in a:
	print(s^i, end=" ")

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

int main() {
string str;
cin >> str;
char c3 = str[2];
char c4 = str[3];
char d5 = str[4];
char d6 = str[5];
if ((c3==c4)&&(d5==d6)) {
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
	
	return 0;
}

Measured memory_bytes: 256
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
std::vector<ll> v;
ll n;
std::vector<ll> memo(100005,-1);
ll dp(ll i)
{
	if(i==0)
		return 0;

	if(i==1)
		return abs(v[1]-v[0]); 

	if(memo[i]==-1)
	return memo[i]=min(dp(i-1)+abs(v[i]-v[i-1]),dp(i-2)+abs(v[i]-v[i-2]));
	else
	return memo[i];
}
int main()
{

	fast
	cin>>n;
	FOR(i,n)
	{
		ll x;
		cin>>x;
		v.pb(x);
	}
	cout<<dp(n-1);


return 0;
}


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int n,m,I,P,Q;
int cnt,head[100010],to[400010],nxt[400010],linker[100010];
bool f,vis[100010];
void add(int x,int y)
{
	cnt++;
	to[cnt]=y;
	nxt[cnt]=head[x];
	head[x]=cnt;
}
void dfs(int x,int fa)
{
	vis[x]=true;
	linker[x]=linker[fa]^1;
	for (int i=head[x];i;i=nxt[i])
	{
		int y=to[i];
		if (y!=fa)
		{
			if (vis[y])
			{
				if (linker[x]==linker[y])
				{
					f=true;
				}
				continue;
			}
			else
			{
				dfs(y,x);
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	int x,y;
	for (int i=0;i<m;i++)
	{
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	for (int i=1;i<=n;i++)
	{
		if (!vis[i])
		{
			if (!head[i])
			{
				I++;
				vis[i]=true;
				continue;
			}
			f=false;
			dfs(i,0);
			if (f)
			{
				P++;
			}
			else
			{
				Q++;
			}
		}
	}
	long long ans=2LL*I*n-1LL*I*I+1LL*P*P+2LL*P*Q+2LL*Q*Q;
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7040
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm> 
#include <vector> 

#define rep(i,x,y) for (int i=x;i<=y;i++)
#define dep(i,y,x) for (int i=y;i>=x;i--)
#define sz(x) (int)(x.size())

using namespace std;

typedef long long LL;

const int maxn=200000+10;

int n,l,r;

char s[maxn];

int main()
{
 scanf("%s",s+1);
 n=strlen(s+1);

 l=1,r=n;
 while (s[l]!='A') l++;
 while (s[r]!='Z') r--;

 printf("%d\n",r-l+1);

 return 0;
}



Measured memory_bytes: 384
import math
import collections
import sys

#input = sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]

a,b,c=MI()
print(max(10*a+b+c,a+10*b+c,10*c+a+b))


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	long long N, A[1 << 18]; // bitシフト表現 262144を表す 2の18乗ですね
	cin >> N;
	long long S;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		S += A[i];
	}
	long long minx = S, sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += A[i];
		minx = min(minx, abs(sum - (S - sum)));
	}
	cout << minx << endl;
}

Measured memory_bytes: 1792
// !Start && !End 
//  0 se divide
//https: //www.youtube.com/watch?v=6Nb-prB-4P0&list=RD6Nb-prB-4P0&start_radio=1

// https: //www.youtube.com/watch?v=eYDI8b5Nn5s
// Electrify my OOOoooooOOOoooOOOOOoooooOOOooo!
#pragma optimise GCC(-O2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll,ll>
#define ve(x) vector<x>
#define f(a,b,c) for(int a=b;a<c;a++)
#define foto(x,v) for(auto x:v)
#define read(t) ll t; cin>>t;
#define reads(t) string t; cin>>t;
#define readarr(arr,n) ll arr[n]; f(i,0,n) cin>>arr[i];
#define forstl(i,v) for(auto &i: v)
#define ln endl
#define Endl endl
#define dbg(x) cout<<#x<<" = "<<x<<ln;
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it<<ln;} cout<<ln;
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cout<<ln;
#define dbgarr(v,s,e) cout<<#v<<" = "; f(i,s,e) cout<<v[i]<<", "; cout<<ln;
#define addEdge(tr,k) f(i,0,k) { ll x,y; cin>>x>>y, tr[x].push_back(y), tr[y].push_back(x);}
#define all(v) v.begin(),v.end()

mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) { uniform_int_distribution<int> uid(0, lim - 1); return uid(rang); }

//														GLOBAL VARS
ll INF =LLONG_MAX;
const ll M= 1000000007;

//														USEFUL FUNCTIONS
ll powm(ll ,ll);

// 														MAIN
int main()
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    //It gets easier day by day, but the hard part is to........
    read(n) read(m)
    readarr(a,n) readarr(b,m)
    ll dp[n+1][m+1];
    memset(dp,0 ,sizeof(dp));
    // dp[0][0] = 1;
    // f(i,0,n) dp[i][0] = 1;
    // f(j,0,m) dp[0][j] = 1;
    f(i,0,n)
    {
        f(j,0,m)
        {
            if(a[i] == b[j])
            {
                dp[i+1][j+1] = (1 + dp[i][j+1] + dp[i+1][j])%M;
            }
            else
            {
                dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] - dp[i][j])%M;
            }
            
        }
    }
    cout<<(dp[n][m]+1+3000*M)%M;
}










//													FUNCTIONS DECLARATIONS
ll powm(ll a, ll b) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%M;
		a=(a*a)%M;
		b>>=1;
	}
	return res;
}


Measured memory_bytes: 31616
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
bool f [100001];
int c [100002];
int N ,L , R ;
int main ()
{
	for ( int i =2; i <=100000; i ++) if (! f [ i ]) for ( int j = i + i ;j <=100000; j += i )
	f[ j ]= true ;
	for ( int i =3; i <=100000; i +=2) if (! f [ i ]&&! f [( i +1)/2]) c [ i ]++;
	for ( int i =3; i <=100000; i ++) c [ i ]+= c [i -1];
	cin >> N ;
	while (N--)
	{
		cin >> L >> R ;
		cout << c [ R ] - c [L -1] << endl;
	}
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
class UnionFind {
public:
	vector < ll > par; // 各元の親を表す配列
	vector < ll > siz; // 素集合のサイズを表す配列(1 で初期化)

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1);
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}
};
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	UnionFind ans(n);
	rep(i, m) {
		int p, q; cin >> p >> q; p--; q--;
		int r; cin >> r;
		ans.merge(p, q);
	}
	set<int>st;
	rep(i, n)st.insert(ans.root(i));
	cout << st.size() << endl;
	return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int sum = 0;
		int d = n;
		while (d > 0) {
			sum += d % 10;
			d /= 10;
		}

		if (n % sum == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


Measured memory_bytes: 35896
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

static const double pi = 3.141592653589793;

struct Problem {

	void Solve() {
		UL N, M; cin >> N >> M;
		UL A, B; cin >> A >> B;
		vector<string> ans;
		rep(i, N) { ans.push_back(string(M, '.')); }
		if (N % 2) {
			rep(p, M / 2) {
				if (A == 0) continue;
				ans[N - 1][p * 2] = '<';
				ans[N - 1][p * 2 + 1] = '>';
				A--;
			}
		}
		if (M % 2) {
			rep(p, N / 2) {
				if (B == 0) continue;
				ans[p * 2][M - 1] = '^';
				ans[p * 2 + 1][M - 1] = 'v';
				B--;
			}
		}
		if (N % 2 && M % 2 && N >= 3 && M >= 3 && A % 2 && B % 2) {
			ans[N - 3][M - 3] = ans[N - 1][M - 2] = '<';
			ans[N - 3][M - 2] = ans[N - 1][M - 1] = '>';
			ans[N - 2][M - 3] = ans[N - 3][M - 1] = '^';
			ans[N - 1][M - 3] = ans[N - 2][M - 1] = 'v';
			A--; B--;
		}
		rep(y, N / 2) {
			rep(x, M / 2) {
				if (ans[y * 2][x * 2] != '.') continue;
				if (A) {
					if (A) { ans[y * 2][x * 2] = '<'; ans[y * 2][x * 2 + 1] = '>'; A--; }
					if (A) { ans[y * 2 + 1][x * 2] = '<'; ans[y * 2 + 1][x * 2 + 1] = '>'; A--; }
				}
				else {
					if (B) { ans[y * 2][x * 2] = '^'; ans[y * 2 + 1][x * 2] = 'v'; B--; }
					if (B) { ans[y * 2][x * 2 + 1] = '^'; ans[y * 2 + 1][x * 2 + 1] = 'v'; B--; }
				}
			}
		}
		if (A > 0 || B > 0) { cout << "NO" << endl; return; }
		cout << "YES" << endl;
		rep(i, ans.size()) { cout << ans[i] << endl; }
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	ll n;
	cin >> n;
	
	if( n % 2 == 0 ) cout << n << endl;
	else cout << n * 2 << endl;

	
	ret 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b,c,tmp,tmp_a,tmp_b;
    while(scanf("%d%d", &a, &b)!=EOF){
        c = 1;
        if(b > a){tmp = a; a = b; b = tmp;}
        tmp_a = a;
        tmp_b = b;
        for(int i=2; i<=tmp_b; i++){
            while(tmp_b%i==0 && tmp_a%i==0){
                c = c*i;
                tmp_b = tmp_b / i;
                tmp_a = tmp_a / i;
            }
        }
        printf("%d %d\n", c, tmp_a*tmp_b*c);
    }
    return 0;
}



Measured memory_bytes: 2032
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main(){
    // input
    int N; cin >> N; 
    vector<int> W(N);
    for (int i = 0; i < N; i++){
        cin >> W.at(i);
    }
    
    // compute
    int sum1 = 0;
    vector<int> dif(N-1);
    for (int i = 0; i < N-1; i++){
        sum1 += W.at(i);
        int sum = accumulate(W.begin(), W.end(), 0);
        int sum2 = sum - sum1;
        dif.at(i) = abs(sum1-sum2);
    }
    
    int ans = *min_element(dif.begin(), dif.end());
    // output
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,i = 0,ans = 1;string s,t;cin >> n >> s >> t;
  while(i<n){
    if(i==0){
      if(s[i]==t[i]){
        ans *= 3;i++;
      } else {
        ans *= 6;i+=2;
      }
    } else {
      if(s[i]==t[i]){
        ans = (ans*((s[i-1]==t[i-1]) ? 2:1))%1000000007;i++;
      } else {
        ans = (ans*((s[i-1]==t[i-1]) ? 2:3))%1000000007;i+=2;
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s, t;
	cin>>s>>t;
	int m=-1, ss=s.size(), ts=t.size();
	for(int i=0; i<ss-ts+1; i++){
		int count=0;
		for(int j=0; j<ts; j++){
			if(s[i+j]==t[j])
				count++;
		}
		m=max(m, count);
	}
	cout<<ts-m<<endl;
	return 0;
}

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

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

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

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

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

#define pb push_back
#define mp(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()
#define asort(x) sort(all(x));
#define dsort(x) sort(all(x), greater<int>())
#define unq(x) x.erase(unique(x.begin(),x.end()),x.end())

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

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

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

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



int main()
{
    //IOS;

    int ahealth,bstrength;
    sfi2(ahealth,bstrength);
    int chealth,dstrength;
    sfi2(chealth,dstrength);

    int i = 2;
    while(true)
    {
        if(ahealth<=0)
        {
            cout<<"No";
            break;
        }
        if(chealth<=0)
        {
            cout<<"Yes";
            break;
        }

        else if(i%2==0)
        {
             chealth -= bstrength;
             i++;
        }
        else if(i%2)
        {
            ahealth -= dstrength;
            i++;
        }
    }

}


Measured memory_bytes: 3760
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ExplodingFreeze
 */

#include <iostream>
#include <fstream>

#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define int long long
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
using pii=std::pair<int,int>;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); <-- PUT IN main()/solve()!

using namespace std;

int n;
double p[3005],ans[3005][3005]={0};
class ICoins {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> n;
		f(i,0,n)
			in >> p[i];
		ans[0][0]=1;
		f(i,0,n)
			f(j,0,i+1)
			{
				ans[i+1][j]+=(ans[i][j]*(1-p[i]));
				ans[i+1][j+1]+=(ans[i][j]*p[i]);
			}
		double chance=0;
		f(i,(n+1)/2,n+1)
			chance+=ans[n][i];
		out << setprecision(12) << chance << "\n";
	}
};


int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ICoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 69120
import sys
input = sys.stdin.readline

N, P = map(int, input().split())
S = list(input().rstrip())

if P in {2, 5}:
    ans = 0
    for i, s in enumerate(S):
        if int(s) % P == 0:
            ans += i+1
else:
    ans = 0
    T = [0]*P
    T[0] = 1
    tmp = 0
    k = 1
    for s in reversed(S):
        tmp = (tmp + k * int(s)) % P
        k = k * 10 % P
        ans += T[tmp]
        T[tmp] += 1

print(ans)

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int n;cin >> n;
  vector<P<int,int>> v;
  for(int i = 0; i < n; ++i){
    int x,l; cin >> x >> l;
    v.emplace_back(x,l);
  }
  sort(v.begin(),v.end(),[](P<int,int>a,P<int,int>b){
      return a.first+a.second < b.first+b.second;
    });
  int pre = -1001001001;
  int ans = n;
  for(int i = 0; i < n; ++i){
    if(pre > v[i].first - v[i].second){
      ans--;
    } else {      
      pre = v[i].first + v[i].second;
    }
  }
  cout << ans << endl;
}


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

const ll INF = 1e9;

matrix prod(const matrix& a, const matrix& b){
	int n = a.size();
	matrix res(n, vector<ll>(n, -INF));
	for(int i = 0;i < n;i++){
		for(int j = 0;j < n;j++){
			for(int k = 0;k < n;k++){
				res[i][k] = max(res[i][k], a[i][j] + b[j][k]);
			}
		}
	}
	return res;
}

matrix power(matrix a, int x){
	int n = a.size();
	matrix res(n, vector<ll>(n, -INF));
	for(int i = 0;i < n;i++) res[i][i] = 0;
	while(x){
		if(x & 1) res = prod(a, res);
		a = prod(a, a);
		x >>= 1;
	}
	return res;
}

int main() {
	int V, E, K;
	cin >> V >> E >> K;
	matrix G(V, vector<ll>(V, -INF));
	for(int i = 0;i < V;i++) G[i][i] = 0;
	for(int i = 0;i < E;i++){
		int u, v;
		ll c;
		cin >> u >> v >> c;
		G[u][v] = max(G[u][v], c);
	}
	int lb = 0, ub = K + 1;
	while(ub - lb > 1){
		int m = (lb + ub) >> 1;
		auto v = power(G, m);
		ll ma = 0;
		for(int i = 0;i < V;i++) ma = max(ma, *max_element(v[i].begin(), v[i].end()));
		if(ma >= K){
			ub = m;
		}
		else{
			lb = m;
		}
	}
	if(ub == K + 1){
		cout << -1 << endl;
		return 0;
	}
	cout << ub << endl;
	if(ub > 100) return 0;
	vector<vector<ll>> dp(ub + 1, vector<ll>(V, -INF));
	for(int i = 0;i < V;i++) dp[0][i] = 0;
	for(int x = 0;x < ub;x++){
		for(int i = 0;i < V;i++){
			for(int j = 0;j < V;j++){
				dp[x + 1][j] = max(dp[x + 1][j], dp[x][i] + G[i][j]);
			}
		}
	}
	int pos = 0;
	for(int i = 0;i < V;i++){
		if(dp[ub][i] > dp[ub][pos]) pos = i;
	}
	vector<int> res;
	res.push_back(pos);
	for(int i = ub;i > 0;i--){
		for(int to = 0;to < V;to++){
			if(dp[i - 1][to] + G[to][pos] == dp[i][pos]){
				res.push_back(to);
				pos = to;
				break;
			}
		}
	}
	assert((int)res.size() == ub + 1);
	reverse(res.begin(), res.end());
	for(int i = 0;i <= ub;i++){
		cout << res[i] << " \n"[i == ub];
	}
}



Measured memory_bytes: 3704
/*
Atcoder ABC152F
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long

int n,m,g[55][55],t;
vector<int> e[55];
int found=0,u=0;
int f[55][1<<21];

void dfs(int x,int pre)
{
	if(x==t)
	{
		found = 1;
		return;
	}
	for(int y=1;y<=n;y++)
		if(g[x][y] && y!=pre)
		{
			dfs(y,x);
			if(found)
			{
				e[g[x][y]].push_back(u);
				return;
			}
		}
}

signed main()
{
	cin>>n;
	for(int i=1,x,y;i<n&&cin>>x>>y;i++)
		g[x][y] = g[y][x] = i;
	cin>>m;
	for(int i=1,x;i<=m&&cin>>x>>t;i++)
	{
		found = 0, u = i;
		dfs(x,0);
	}
	f[0][0] = 1;
	for(int i=0;i<n-1;i++)
		for(int s=0;s<=(1<<m)-1;s++)
		{
			f[i+1][s] += f[i][s];
			int t=s;
			for(int j=0;j<e[i+1].size();j++)
				t |= 1<<e[i+1][j]-1;
			f[i+1][t] += f[i][s];
		}
	cout<<f[n-1][(1<<m)-1]<<endl;
	
	return 0;
}

Measured memory_bytes: 405256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    long long int l, r, a, b;
    long long int cnt = 1, mod = 1e9;

    cin >> l >> r;

    while (cnt * 2019 <= r) {
        if (cnt * 2019 >= l && cnt * 2019 <= r) {
            cout << 0 << endl;
            return (0);
        }
        cnt++;
    }

    for (long long int i = l; i < r; i++) {
        for (long long int j = i+1; j <= r; j++) {
            if (mod > i*j%2019) {
                mod = i*j%2019;
            }
        }
    }

    cout << mod << endl;
}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
n, k = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b = map(int, input().split())
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
s = [0]
d = [-1] * n
while s:
    p = s.pop()
    if d[p] == -1:
        s.append(p)
        d[p] = -2
        for node in g[p]:
            if d[node] == -1:
                s.append(node)
    else:
        res = 1
        if s:
            t = k - 2
        else:
            t = k - 1
        f = 1
        for node in g[p]:
            if d[node] != -2:
                f *= t
                f %= MOD
                t -= 1
                res *= d[node]
                res %= MOD
        d[p] = res * f
print(d[0] * k % MOD)


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

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

  ll X; cin >> X;
  ll ans = 0;
  ans += (X / 500) * 1000;
  X %= 500;
  ans += (X / 5) * 5;
  cout << ans << '\n';
  return 0;
}

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

int main(){
  int n, m, l;
  cin >> n >> m >> l;
  int A[n][m], B[m][l];
  long C[n][l] = {};

  for ( int i = 0; i < n; i++ )
    for ( int k = 0; k < m; k++ )
      cin >> A[i][k];

  for ( int k = 0; k < m; k++ )
    for ( int j = 0; j < l; j++ )
      cin >> B[k][j];

  for ( int i = 0; i < n; i++ ){
    for ( int j = 0; j < l; j++ ){
      for ( int k = 0; k < m; k++ ){
        C[i][j] += A[i][k]*B[k][j];
      }
      if ( j ) cout << " ";
      cout << C[i][j];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3220
class Dice():
	def __init__(self, label):
		self.d = label
		
	def __eq__(self, other):
		return (self.d[1] == other.d[1] and self.d[2] == other.d[2] and self.d[3] == other.d[3] and self.d[4] == other.d[4] and self.d[5] == other.d[5] and self.d[6] == other.d[6])
	
	def __ne__(self, other):
		return (self.d[1] != other.d[1] or self.d[2] != other.d[2] or self.d[3] != other.d[3] or self.d[4] != other.d[4] or self.d[5] != other.d[5] or self.d[6] != other.d[6])
	
	def roll(self, drt):
		if drt == 'N':
			self.d[1], self.d[2], self.d[6], self.d[5] = self.d[2], self.d[6], self.d[5], self.d[1]
		elif drt == 'E':
			self.d[1], self.d[3], self.d[6], self.d[4] = self.d[4], self.d[1], self.d[3], self.d[6]
		elif drt == 'S':
			self.d[2], self.d[6], self.d[5], self.d[1] = self.d[1], self.d[2], self.d[6], self.d[5]
		elif drt == 'W':
			self.d[4], self.d[1], self.d[3], self.d[6] = self.d[1], self.d[3], self.d[6], self.d[4]
		elif drt == 'r':
			self.d[2], self.d[3], self.d[5], self.d[4] = self.d[4], self.d[2], self.d[3], self.d[5]
		elif drt == 'l':
			self.d[4], self.d[2], self.d[3], self.d[5] = self.d[2], self.d[3], self.d[5], self.d[4]
	
	def printl(self, lct):
		print(self.d[lct])
		
label = [0]	
label.extend(list(map(int, input().split())))
dice1 = Dice(label)

label2 = [0]
label2.extend(list(map(int, input().split())))
dice2 = Dice(label2)

S1 = 'NNNNENNNNENNNNENNNNrNNNNllNNNN'
leng = len(S1)

for j in range(leng):
		if dice1 == dice2:
			print("Yes")
			break
		dice2.roll(S1[j])

if dice1 != dice2:
	print("No")

	

Measured memory_bytes: 7924
function Main(inp) {
    var input = inp.split("\n");
    var n = Number(input[0]);
    var nums = input[1].split(' ').map(function(n) {return Number(n);});
    var i, len = nums.length, max = 0, j;
    for (i = 0; i < len; i++) {
        for (j = 0; j < len; j++) {
            if (i === j) continue;
            var diff = Math.abs(nums[i] - nums[j]);
            if (max < diff) {
                max = diff;
            }
        }
    }
    console.log(max);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

struct war
{
	ll a; ll b;
};
ll const MAX = 100005;
war x[MAX];

bool order(war s, war t) {
	return s.b < t.b;
}
int main() {
	ll n, m;
	cin >> n >> m;
	REP(i, 1, m) {
		ll s, t;
		cin >> s >> t;
		x[i] = { s,t };
	}
	sort(x + 1, x + m + 1, order);
	ll ans = 0;
	ll now = 0;
	REP(i, 1, m) {
		if (now <= x[i].a) {
			ans++;
			now = x[i].b;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    string s;
    cin >> s;
    list<int> li;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '0') li.push_back(0);
        else if(s[i] == '1') li.push_back(1);
        else{
            if(li.empty()) continue;
            else li.pop_back();
        }
    }    
    for(auto p:li){
        cout << p;
    }
    cout << endl;
}

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

void traceArray(int A[],int N){
    for(int i = 0; i < N; i++){
        if(i > 0){
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
}

void insertionSort(int A[],int N){
    for(int i = 1; i < N; i++){
        int v = A[i];
        for(int j = i-1; j >= 0; j--){
            if(v < A[j]){
                A[j+1] = A[j];
                A[j] = v;
            }
        }
        traceArray(A,N);
    }
}

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    traceArray(a,n);
    insertionSort(a,n);
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int n;
  cin >> n;
  ll a[n];
  ll min_diff = 999999999999999;
  ll where = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);
  for (int i = 0; i < n-1; i++) {
    if (abs(a[n-1] - (2LL * a[i])) < min_diff) {
      min_diff = abs(a[n-1] - (2LL * a[i]));
      where = i;
    }
  }
  cout << a[n-1] << " " << a[where] << endl;
  return 0;
}

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

int main() {
    int s;cin>>s;
    int ans = 1;
    while(1){
        if(s==1||s==2){
            cout<<4<<endl;
            return 0;
        }
        if(s%2==0)s/=2;
        else s=3*s+1;
        if(s==4){
            cout<<ans+4<<endl;
            return 0;
        }
        ans++;
    }
}

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

using namespace std;

int func(int x, int y){
  int z = 1;
  while(z != 0){
    z = x % y;
    x = y;
    y = z;
  }
  return x;
}

int main(){
  int a, b, x;
  cin >> a >> b;
  x = func(a, b);
  cout << (long long int)a * b / x << endl;
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		int m = 1000000007;
		long ans = 0;
		long[] memo = new long[k + 1];
		for (int i = k; i > 0; i--) {
			int x = k / i;
			long val = power(x, n, m);
			for (int j = 2; j <= k; j++) {
				int b = i * j;
				if (b <= k) {
					val -= memo[b];
					val += m;
					val %= m;
				} else {
					break;
				}
			}
			memo[i] = val;
			ans += val * i % m;
			ans %= m;
		}
		System.out.println(ans);
	}

	static long power(long x, long n, int m) {
		if (n == 0) {
			return 1;
		}
		long val = power(x, n / 2, m);
		val = val * val % m;
		if (n % 2 == 1) {
			val = val * x % m;
		}
		return val;
	}
}


Measured memory_bytes: 36852
import math
def main():
  n,m,x,y = list(map(int,input().split()))
  xv = list(map(int,input().split()))
  yv = list(map(int,input().split()))
  flg=0
  if max(xv)<=min(yv):
    for i in range(x+1,y+1):
      if(max(xv) < i )and(i <= min(yv)):
        flg=1
        break
  if flg==1:
    print("No War")
  else:
    print("War")
    
main()

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

typedef complex<double> Point;

double cross(Point a, Point b){
    return (conj(a)*b).imag();
}

int main(){
    Point V[3], P;
    while(true){
        double x, y;
        for(int i=0; i<3; i++){
            cin >> x >> y;
            V[i] = {x, y};
        }
        cin >> x >> y;
        P = {x, y};
        
        if(!cin)break;
        
        int sum = 0;
        for(int i=0; i<3; i++){
            sum += cross(V[(i+1)%3]-V[i], (P-V[i])) > 0;
        }
        cout << (sum==0 || sum==3? "YES": "NO") << endl;
    }
    return 0;
}



Measured memory_bytes: 3068
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#define NUM 100000
using namespace std;

int base[NUM + 1];
int N, M, K;

vector<int> F[NUM + 1];
vector<int> B[NUM + 1];

int base_num[NUM + 1];

void init(){
    for(int i = 1; i <= N; i++){
        base[i] = i;
    }
}

int update_base(int a){
    vector<int> v;
    while(a != base[a]){
        v.push_back(a);
        a = base[a];
    }
    
    for(int i = 0; i < v.size(); i++){
        base[v[i]] = a;
    }

    //printf("update: %d %d\n", a, base[a]);

    return a;
}

void do_union(int a, int b){
    int a_base = update_base(a);
    int b_base = update_base(b);

    if(a_base != b_base){
        base[b_base] = a_base;
    }
}

bool do_find(int a, int b){
    int a_base = update_base(a);
    int b_base = update_base(b);
    if(a_base == b_base){
        return true;
    }else{
        return false;
    }
}

int num_block_and_potential_friend(int a){
    int count = 0;
    for(int i = 0; i < B[a].size(); i++){
        if(do_find(a, B[a][i])){
            count++;
        }
    }
    return count;
}

int main(void){
    scanf("%d", &N);
    scanf("%d", &M);
    scanf("%d", &K);

    init();

    for(int i = 0; i < M; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        F[a].push_back(b);
        F[b].push_back(a);

        do_union(a, b);
    }

    for(int i = 1; i <= N; i++){
        update_base(i);
    }

    for(int i = 0; i < K; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        B[a].push_back(b);
        B[b].push_back(a);
    }

    for(int i = 1; i <= N; i++){
        base_num[i] = 0;
    }

    for(int i = 1; i <= N; i++){
        base_num[base[i]]++;
    }

    for(int i = 1; i <= N; i++){
        printf("%d ", base_num[base[i]] - (int)F[i].size() - num_block_and_potential_friend(i) - 1);
        //printf("%d ", base_num[base[i]]);
        //printf("%d ", (int)F[i].size());
        //printf("%d ", num_block_and_potential_friend(i));
        //printf("\n");
        //printf("%d ", base[i]);
    }
    printf("\n");
}


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

int main() {
	int x, y;
	cin >> x >> y;
	bool ans = false;
	for (int kame = 0; kame <= x; kame++) {
		int tsuru = x - kame;
		if (tsuru*2 + kame*4 == y) ans = true;
	}
	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>

int main(){
  int a,b,c,d;
  scanf("%d %d",&a,&b);
  if(1<=a && a<=1000000000 && 1<=b && b<=1000000000){
  c = a	/ b;
  d = a	% b;
  double f = a;
  double g = b;
  double e = f / g;
  printf("%d %d %.5lf\n",c,d,e);
  }
  return 0;
}

Measured memory_bytes: 1068
#include<bits/stdc++.h>
using namespace std; 
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
 
typedef long long int ll; 
typedef long double ld; 
 
#define MAX 300005
#define endl '\n'
#define UPPER 1000000000

int main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	cin>>s;
	
	ll cur = 0;
	for(char c: s){
		cur = (cur+(c-'0'))%9;
	} 
	if(cur==0){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}


Measured memory_bytes: 3704