akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    Scanner in;
    int lineNum;
    int colNum;
    char[][] array;
    String temp;
    int[][] direction1={{-1,-1},{1,-1},{-1,1},{1,1}};
    int[][] direction2={{0,1},{1,0},{-1,0},{0,-1}};

    Main(){
        in=new Scanner(System.in);

        lineNum=in.nextInt();
        colNum=in.nextInt();

        array=new char[lineNum][colNum];

        for(int i=0;i<lineNum;i++){
            temp=in.next();
            for(int j=0;j<colNum;j++){
                array[i][j]=temp.charAt(j);
            }
        }
    }

    public void cal(){
        char[][] result=new char[lineNum][colNum];
        int xtemp=0;
        int ytemp=0;
        int count=0;

        for(int i=0;i<lineNum;i++){
            for(int j=0;j<colNum;j++){
                if(array[i][j]=='#'){
                    result[i][j]='#';
                }
                else{
                    for(int[] k:direction1){
                        xtemp=i+k[0];
                        ytemp=j+k[1];

                        if(xtemp<0 || ytemp<0 || xtemp>=lineNum || ytemp>=colNum){
                            continue;
                        }
                        else if(array[xtemp][ytemp]=='#'){
                            count++;
                        }
                    }

                    for(int[] l:direction2){
                        xtemp=i+l[0];
                        ytemp=j+l[1];

                        if(xtemp<0 || ytemp<0 || xtemp>=lineNum || ytemp>=colNum){
                            continue;
                        }
                        else if(array[xtemp][ytemp]=='#'){
                            count++;
                        }
                    }

                    array[i][j]=(char)(count+48);
                    count=0;
                }
            }
        }

        for(int i=0;i<lineNum;i++){
            for(int j=0;j<colNum;j++){
                System.out.print(array[i][j]);
            }
            System.out.println();
        }
    }

    public static void main(String args[]){
        Main m=new Main();
        m.cal();
    }
}


Measured memory_bytes: 22356
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<bits/stdc++.h>
using namespace std;

int main()
{
	
	string w;
	cin>>w;
	
	int count;
	int i,j;
	for(i=0;i<w.size();i++)
	{
		  count=0;
	     for(j=0;j<w.size();j++)
	     {
	     	 
	     	   if(w[i]==w[j])
	     	   {
	     	   	
	     	       count++;	
	     	   	
			   }
	     	
	     		
		 }
		 
		 
		 if(count%2!=0)
		 {
		 	
		 	break;
		 	
		 }
		
		
	
	}
	
	
	
	
	if(i==w.size())
	{
		
		cout<<"Yes"<<endl;
		
	}
	
	
	else
	{
		
		
		cout<<"No"<<endl;
	}
	

	return 0;
	
}

Measured memory_bytes: 3628
#a, b, c, d = (int(i) for i in input().split())  
#W = [int(i) for i in input().split()] 
# N= (int(input()))

N, M = (int(i) for i in input().split())  
flag = 0
A_list = []
B_list = []
AB_list = []
for i in range(N):
    a,b= (int(j) for j in input().split())  
    A_list.append(a)
    B_list.append(b)
    AB_list.append([a,b])
    pass
AB_list = sorted(AB_list, key=lambda x: x[0])
#print(AB_list)
now = 0
m_cnt = 0
n_cnt = 0
for ab in AB_list:
    #print(n_cnt + (ab[1]))
    if n_cnt + ab[1] >= M:
        a = M - n_cnt
        n_cnt += a
        m_cnt += (a * ab[0])
        break
    else:
        n_cnt += ab[1]
        m_cnt += (ab[1] * ab[0])
        pass

print(m_cnt)
# k_list = []
# s_list = []
# p_list = []
# for i in range(M):
#     for j in range(N):
#         a = [int(i) for i in input().split()] 
#         k_list.append(a[0])
#         s_list.append(a[1:])
#         pass
#     pass
# p_list = [int(i) for i in input().split()] 

# lamp_list = []



# #N = int(input())
# # A = [int(i) for i in input().split()] 
# #S_dict = {}
# #P_dict = {}
# # for i in range(N):
# #     tmp = input()
# #     S = tmp.split()[0]
# #     P = int(tmp.split()[1])
# #     if S in S_dict.keys() and P < S_dict[S]:
# #         pass
# #     else:
# #         S_dict[S] = P
# #         pass
# #     pass
# # S_dict = sorted(S_dict.items())

# # print(type(S_dict))
# # name_lisy = []

# # for k in S_dict:
# #     name_lisy.append(k)
# #     pass
# # print(name_lisy)
# S_list = []
# P_list = []
# for i in range(N):
#     tmp = input()
#     S = tmp.split()[0]
#     P = int(tmp.split()[1])
#     #print(S,P)
#     S_list.append([S,P])
#     #P_list.append(P)
#     pass
# #S_list.sort()
# #print(S_list)
# sorted_S_list = sorted(S_list, key=lambda x:x[1], reverse=True)
# sorted_S_list = sorted(sorted_S_list, key=lambda x:x[0])
# #print(sorted_S_list)

# for i,k in enumerate(sorted_S_list):
#     for j,l in enumerate(S_list):
#         if sorted_S_list[i] == S_list[j]:
#             print(j+1)
#             break
#         pass
#     pass


# #print(P_list)

# for i in range(M):
#     # A.sort()
#     if min(A) < C_list[i]:
#         for j in range(B_list[i]):        
#             if min(A) < C_list[i]:
#                 A.append(C_list[i])
#                 pass
#             pass
#         A.sort(reverse=True)
#         A = A[:N]
#         pass
#     pass
# #sum(A[:N-1])
# print(sum(A[:N]))
# for i in range(M):
#     A.sort()
#     cnt = 0
#     for j in range(N):
#         if cnt < B_list[i] and A[j] < C_list[i]:
#             A[j] = C_list[i]
#             cnt += 1
#             pass
#         pass
#     #print(A)
#     pass
# print(sum(A))






# L_max = max(L_list)
# R_min = min(R_list)
# for i in range(M):
#     pass

# if R_min-L_max+1 < 0:
#     print("0")
# else:
    
#     print(R_min-L_max+1)
# if A <= 5:
#     print(0)
# elif 5 < A and A <= 12:
#     print(int(B/2))
# else:
#     print(B)


Measured memory_bytes: 23624
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  200001

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b, c, d;
    
    scanf("%d%d%d%d", &a, &b, &c, &d);
    
    if (a+b<c+d) {
        printf("Right");
    } else if (a+b>c+d) {
        printf("Left");
    } else {
        printf("Balanced");
    }
    
    return 0;
}



Measured memory_bytes: 1732
import java.util.*;


import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int a = ni();
		int b = ni();
		int socket = 1;
		int result = 0;
		while(socket < b) {
			result++;
			socket += a - 1;
		}
		System.out.println(result);		
	}

	//Switch input source (stdin/file)
	private static BufferedReader br  = new BufferedReader(new InputStreamReader(System.in));
	public static void main(String[] args){
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		} 
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 22484
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

long long dp[110][100010];
signed main(){
    cin.tie(0); 
    ios::sync_with_stdio(false);
    int n,w_allow;
    int w[110],v[110];
    cin >> n >> w_allow;
    for(int i=1;i<=n;i++){
        cin >> w[i] >> v[i];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=w_allow;j++){
            if(w[i] <= j){
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]] + v[i]);
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    cout << dp[n][w_allow] << "\n";
    return 0;
}



Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int n;
    cin>>n;
    vector<ll> a(n+1,INT_MAX),b(n+1,1000);
    Fr(i,n){
        cin>>a[i];
        b[i]=b[i-1];
        fr(j,i) chmax(b[i],b[j]/a[j]*a[i]+b[j]%a[j]);
    }
    cout<<b[n]<<'\n';
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

Measured memory_bytes: 3596
#include <iostream>
#define MAX 100000
using namespace std;

int n;

void countingSort(int *A, int *B, int k) {
    int C[MAX];

    for(int i=0; i<=k; i++) {
        C[i] = 0;
    }

    for(int j=0; j<n; j++) {
        C[A[j]]++;
    }

    for(int i=1; i<=k; i++) {
        C[i] = C[i] + C[i-1];
    }

    for(int j=n-1; j>=0; j--) {
        B[C[A[j]]-1] =  A[j];
        C[A[j]]--;
    }
}

int main() {
    int max = 0;

    cin >> n;
    int A[n], B[n];
    for(int i=0; i<n; i++) {
        cin >> A[i];
        if(max<A[i]) {
            max = A[i];
        }
    }

    countingSort(A, B, max);

    for(int i=0; i<n; i++) {
        cout << B[i];
        if(i!=n-1) {
            cout << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 18716
#include<stdio.h>

int main(void){
    int a,b,x;
    scanf("%d%d",&a,&b);
    if(a%2==0){
        x = 12.5*a;
    }else{
        x = (12.5*a)+1;
    }
    
    for(;(int)(x*0.08)<=a;x++){
        //printf("%d",(int)(x*0.1));
        if((int)(x*0.1)==b){
            printf("%d",x);
            return 0;
        }
    }
    printf("-1");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n , m ;
    long long k;
    cin >> n >> m >> k;
    vector<long long> a(n + 1) , b(m + 1)  ;
    for( int i  = 1 ; i<=n ; i++){
        cin>>a[i];
    }
    for(int i = 1 ; i<= m ;i++){
        cin >> b[i];
    }

    vector< long long > prfxA( n+1 , 0 ) , prfxB(m+1,0);
    for(int i = 1; i <=n ;i++){
        prfxA[i] = prfxA[i-1] + a[i];
    }
    for(int i = 1 ; i<= m ; i++){
        prfxB[i] = prfxB[i-1] + b[i];
    }

    int ans = 0;
    for(int i = 0 , j = m; i<=n && prfxA[i] <= k ; i++ ){
        while(prfxA[i] + prfxB[j] > k){
            j--;
        }
        
        ans = max(ans ,  i + j );
    }

    cout <<  ans;
}

Measured memory_bytes: 9600
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (sx, sy, tx, ty) = (v[0], v[1], v[2], v[3]);
    for _ in sx..tx {
        print!("R");
    }
    for _ in sy..ty {
        print!("U");
    }
    for _ in sx..tx {
        print!("L");
    }
    for _ in sy..ty {
        print!("D");
    }

    print!("D");
    for _ in sx..tx + 1 {
        print!("R");
    }
    for _ in sy..ty + 1 {
        print!("U");
    }
    print!("L");

    print!("U");
    for _ in sx..tx + 1 {
        print!("L");
    }
    for _ in sy..ty + 1 {
        print!("D");
    }
    print!("R");

    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
n,m = map(int,input().split())
student = []
check = []
ans = []

def add(num,point):
    for i in range(num):
        point.append(input().split())
    for i in range(len(point)):
        for j in range(len(point[i])):
            point[i][j] = int(point[i][j])

add(n,student)
add(m,check)

for i in range(n):
    for j in range(m):
        ans.append(abs(student[i][0] - check[j][0]) + abs(student[i][1] - check[j][1]))
    print(ans.index(min(ans)) + 1)
    ans = []

Measured memory_bytes: 3316
"""
問題文 { 1 , 2 , . . . , n } の順列 p = { p 1 , p 2 , . . . , p n } があります。
以下の条件を満たすような p i ( 1 < i < n ) がいくつあるかを出力してください。
p i − 1 , p i , p i + 1 の 3 つの数の中で、 p i が 2 番目に小さい。
制約 入力は全て整数である。
3 ≤ n ≤ 20 p は { 1 , 2 , . . . , n } の順列である。
入力 入力は以下の形式で標準入力から与えられる。
n
p 1 p 2 . . . p n
"""

n = int(input())
a = list(map(int,input().split()))
count = 0

for i in range(1,n-1):
    if a[i-1] < a[i] <a[i+1] or a[i+1] < a[i] < a[i-1]:
        count += 1
print(count)

Measured memory_bytes: 9184
import sys
n,k = map(int,input().split())
a = list(map(int,input().split()))

dp = [sys.maxsize]*n
dp[0]=0

#print(dp)
for i in range(n):
  for j in range(i+1,i+k+1):
    if j<n:
      dp[j] = min(dp[j],dp[i]+abs(a[i]-a[j]))
  #print(dp)
      
print(dp[n-1])

Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

ll q,h,s,d;
ll n;

int main(){
    cin >> q >> h >> s >> d;
    cin >> n;
    ll lp = min((min(2*q,h)*2),s);
    ll tp = min(lp*2,d);
    ll res = 0;
    res += (n/2)*tp;
    if(n%2){
        res += lp;
    }
    put(res);
    return 0;
}


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

using namespace std;
using ll = long long;

int const NMAX = int(100)+1;
int const WMAX = int(1e5)+1;

ll dp[NMAX][WMAX] = {0,};
int main() {
    int n, w;
    cin >> n >> w;

    vector<int> vw(n), vv(n);
    for (int i=0; i<n; ++i) {
        cin >> vw[i] >> vv[i];
    }

    for (int i=1; i<=n; ++i) {
        for (int j=0; j<=w; ++j) {
            dp[i][j] = dp[i-1][j];
            if (j<vw[i-1]) continue;

            dp[i][j] = max(dp[i][j], dp[i - 1][j - vw[i - 1]] + vv[i - 1]);
        }
    }

    ll ans = 0;
    for (int i = 0; i <= w; ++i) ans = max(ans, dp[n][i]);
    cout << ans << endl;
}

Measured memory_bytes: 78336
#include<stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int a[n];
    int ans[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        ans[i] = 0;
    }
    for(int i = 0; i < n; i++) {
        ans[a[i]-1] = i + 1;
    }
    printf("%d", ans[0]);
    for(int i = 1; i < n; i++) {
        printf(" %d", ans[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	string s;
	cin >> s;
	int mini = INF;
	for( int i = 0; i+3 <= s.l_ength(); ++i ){
		int x = 100*(s[i]-'0') + 10*(s[i+1]-'0') + (s[i+2]-'0');
		mini = min( mini, abs(753-x) );
	}
	cout << mini << endl;
	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    string t, d;
    rep(i, q) {
        string a, b;
        cin >> a >> b;
        t += a;
        d += b;
    }

    reverse(all(t));
    reverse(all(d));

    //cout << t << ' ' << d << endl;

    int l = -1, r = n;
    rep(i, q) {
        if(l != n-1 and s[l+1] == t[i] and d[i] == 'L') l++;
        if(r and s[r-1] == t[i] and d[i] == 'R') r--;
        if(l != -1 and s[l] == t[i] and d[i] == 'R') l--;
        if(r != n and s[r] == t[i] and d[i] == 'L') r++;
    }

    int ans = r-l-1;
    if(ans < 0) ans = 0;

    cout << ans << endl;
}

Measured memory_bytes: 1024
A, B = input().split()

A = int(A)

if '.' in B:
    idx_dot = B.index('.')
    level = len(B) - 1 - idx_dot
    B_int = ''
    for Bi in list(B):
        if Bi != '.': B_int += Bi
    B_int = int(B_int)
    #
    ans = (A * B_int) // (10 ** level)
else:
    B = int(B)
    ans = A * B

print(ans)

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <cmath>
#include <stdio.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    int n;
    cin >> n;

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

    ll height = v[0];
    height --;
    for(int i = 1; i < n; i++){
        if(v[i] - height >= 1){
            height = v[i] - 1;
        }
        else if(v[i] - height == 0){
            height = v[i];
        }
        else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

}

Measured memory_bytes: 1024
#include <string.h>                                                             
#include <stdio.h>                                                              
                                                                                
int main(void){                                                                 
  char s[100000];                                                               
  scanf("%s",s);                                                                
  int size = strlen(s);                                                         
                                                                                
  int i;                                                                        
  for(i = 0; i < size; i = i + 2){                                              
    printf("%c",s[i]);                                                          
  }                                                                             
  printf("\n");                                                                 
  return 0;                                                                     
}           

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
typedef long long ll;
int n;char s[15];ll num[5];
int main() {
    scanf("%d",&n);
    while(n--) {
        scanf("%s",s);
        if(s[0]=='M') num[0]++;
        else if(s[0]=='A') num[1]++;
        else if(s[0]=='R') num[2]++;
        else if(s[0]=='C') num[3]++;
        else if(s[0]=='H') num[4]++;
    }
    ll ans=0;
    for(int i=0;i<5;i++) for(int j=i+1;j<5;j++) for(int k=j+1;k<5;k++) ans+=num[i]*num[j]*num[k];
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin>> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  cout<<vec.at(N/2)-vec.at(N/2-1)<<endl;
}


Measured memory_bytes: 3768
M = 10**9+7
S = input()
D = 13
# N = len(S)
dp = [0 for d in range(D)]
dp[0] = 1
mul = 1
for i in range(len(S)-1, -1, -1):
    nextDP = [0 for d in range(D)]
    c = S[i]
    if c == '?':
        for k in range(10):
            for j in range(D):
                nextDP[(k*mul+j)%D] += dp[j]
                nextDP[(k*mul+j)%D] %= M
    else:
        k = int(c)
        for j in range(D):
            nextDP[(k*mul+j)%D] += dp[j]
            nextDP[(k*mul+j)%D] %= M

    mul *= 10
    mul %= D
    dp = nextDP
print(dp[5])


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

long long MOD=1000000007;

int main(){
    //input
    long long N,M;
    cin >> N >> M;
    long long S[N+1], T[M+1];
    long long i,j;
    for(i=1; i<=N; i++){
        cin >> S[i];
    }
    for(j=1; j<=M; j++){
        cin >> T[j];
    }

    //calc
    long long sum[N+1][M+1];
    for(i=0; i<=N; i++){
        sum[i][0]=1;
    }
    for(j=0; j<=M; j++){
        sum[0][j]=1;
    }
    for(i=1; i<=N; i++){
        for(j=1; j<=M; j++){
            if(S[i]==T[j]){
                sum[i][j]=sum[i-1][j]+sum[i][j-1];
                sum[i][j]%=MOD;
            }else{
                sum[i][j]=sum[i-1][j]+sum[i][j-1]+MOD-sum[i-1][j-1];
                sum[i][j]%=MOD;
            }      
        }
    }

    //answer
    cout << sum[N][M] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 34760
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   int a,b;cin>>a>>b;
   int res = 1;
   int cnt = 0;
   for(int i=1;res<b;i++){
       res--;
       res += a;
       cnt++;
   }
   cout<<cnt;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF 1000000013
using namespace std;
int dp[100010][3];

int main(){
  int n;
  cin >> n;
  int a[n],b[n],c[n];
  for(int i=0;i<n;i++) cin >> a[i] >> b[i] >> c[i];
  dp[0][0]=a[0],dp[0][1]=b[0],dp[0][2]=c[0];
  for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  cout << max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}) << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define ll long  long 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const unsigned int M = 1000000007;


  
int main()
{
	

    ll n;
    cin>>n;
    string s;
    cin>>s;
    int r=0,w=0,res=0;
    for (int i = 0; i < s.size(); ++i)
    {
      if(s[i]=='W')
      w++;
      else
      r++;
    }
     for(int i=r;i<s.size();i++)
     {
       if(s[i]=='R')
     	res++;
     }
  
  cout<<res<<endl;
      
return 0;
}




Measured memory_bytes: 3696
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] li = new int[n];
        for(int i = 0; i < n; i++){
            li[i] = sc.nextInt();
        }
        long ans = Long.MAX_VALUE;
        for(int i = -100; i <= 100; i++){
            long tmp = 0;
            for(int j = 0; j < n; j++){
                tmp += Math.pow(Math.abs(i-li[j]),2);
            }
            ans = Math.min(ans,tmp);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	int i, j;
	for (i = 0; i < n; i++)cin >> a[i] >> b[i] >> c[i];
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];

	for (i = 1; i < n; i++) {
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
	}


	cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]) << endl;

	return;
}

int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	solve();
	return 0;
}


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

int main() {
    int x1, y1, x2, y2, x3, y3, x4, y4;
    cin >> x1 >> y1 >> x2 >> y2;

    x3 = x2 - y2 + y1;
    y3 = y2 + x2 - x1;
    x4 = x1 - y2 + y1;
    y4 = y1 + x2 - x1;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int uint64;
typedef long long int          int64;
 
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void get_N (int64 *n)
{
  
  (void)scanf("%lld", n);

  return;
}

void get_NK (int64 *n, int64 *k)
{
  
  (void)scanf("%lld %lld", n, k);

  return;
}

void get_N1234 (int64 *n1, int64 *n2, int64 *n3, int64 *n4)
{

  if (n2 == NULL) {
    (void)scanf("%lld", n1);
    return;
  }
  if (n3 == NULL) {
    (void)scanf("%lld %lld", n1, n2);
    return;
  }
  if (n4 == NULL) {
    (void)scanf("%lld %lld %lld", n1, n2, n3);
    return;
  }
  (void)scanf("%lld %lld %lld %lld", n1, n2, n3, n4);
  return;
}

void omit_LF (void)
{
  char c;
  
  (void)scanf("%c", &c);
  return;
}

char *get_S (int64 n)
{
  char *buf;

  buf = (char *)malloc((size_t)(n * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  (void)scanf("%s", buf);

  return buf;
}

char *get_SN (int64 max, int64 *size)
{
  char *buf;
  int  n;

  buf = (char *)malloc((size_t)(max * sizeof(char)));
  if (buf == NULL) {
    return NULL;
  }

  (void)scanf("%s", buf);

  n = strlen(buf);

  *size = n;
  
  return buf;
}

int64 *get_NSeq (int64 n)
{
  int64 *buf;
  int64 i;

  buf = (int64 *)malloc((size_t)(n * sizeof(int64)));
  for (i=0; i<n; i++) {
    get_N(&buf[i]);
  }

  return buf;
}

typedef struct _tmp_t {
  int64    a;
  int64    b;
} tmp_t;

typedef int64 simple_t;

int compare_simple(const void *a, const void *b)
{
  simple_t *x;
  simple_t *y;

  x = (simple_t *)a;
  y = (simple_t *)b;

  if (x > y) return 1;
  if (y < x) return -1;

  return 0;
}
void qsort_simple (simple_t *array, int size)
{
  qsort(array, size, sizeof(simple_t), compare_simple);
}

int compare_a(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->a > y->a) return 1;
  if (x->a < y->a) return -1;

  return 0;
}

int compare_b(const void *a, const void *b)
{
  tmp_t *x;
  tmp_t *y;

  x = (tmp_t *)a;
  y = (tmp_t *)b;

  if (x->b > y->b) return 1;
  if (x->b < y->b) return -1;

  return 0;
}

void qsort_a (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_a);
}

void qsort_b (tmp_t *array, int size)
{
  qsort(array, size, sizeof(tmp_t), compare_b);
}


int resolve1()
{
  int64 a;
  int64 total;

  get_N(&a);

  total = a + a*a + a*a*a;

  printf("%lld", total);
  
  return 0;
}

int resolve2()
{
  int64 N,M;
  int64 *A;
  int64 i;
  int64 total = 0;
  int64 play=0;
  
  get_NK(&N, &M);
  A = get_NSeq(M);

  for (i=0; i < M; i++) {
    total += A[i];
  }

  if (N >= total) {
    play = N - total;
  } else {
    printf("-1");
    return 0;
  }

  printf("%lld",play);
  return 0;
}


void resolve3()
{
  int64 size;
  char *S, *T;
  int i;
  int64 num = 0;
  
  S = get_SN((2*(10*10*10*10*10)+1), &size);
  T = get_S(size);

  for (i=0; i < size; i++) {
    if (S[i] != T[i]) {
      num++;
    }
  }

  printf("%lld", num);
  return 0;
}

int main()
{
  resolve3();

  return 0;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  A+=B;
  C+=D;
  if (A>C){
    cout << "Left" << endl;
  }
  else if(A==C){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

enum { U, B, L, F, R, D };
struct Dice {               //   .    .  U(2)   .
    int face[6];            // B(5) L(4) F(0) R(1)
    Dice() {                //   .    .  D(3)   .
        face[F] = 0; face[R] = 1; face[U] = 2;
        face[B] = 5; face[L] = 4; face[D] = 3;
    }
    int find_face(int f) {
        for (int i = 0; i < 6; i++) if (face[i] == f) return i;
        return -1;
    }
    void turn(int dir) {
        switch (dir) {
            case R: rotate(U, R, D, L); break;
            case B: rotate(U, B, D, F); break;
            case L: rotate(U, L, D, R); break;
            case F: rotate(U, F, D, B); break;
            case U: rotate(F, R, B, L); break;  // 上から見て反時計回り
            case D: rotate(F, L, B, R); break;  // 下から見て反時計回り
        }
    }
    int& operator[](int n) { return face[n]; }
    const int& operator[](int n) const { return face[n]; }
    vector<Dice> all_rolls() {              // 24 通り
        vector<Dice> res;
        for (int k = 0; k < 6; k++) {
            for (int i = 0; i < 4; i++) {
                res.push_back(*this);
                turn(R);
            }
            turn(k % 2 == 1 ? U : F);
        }
        return res;
    }
    void rotate(int a, int b, int c, int d) {
        int t = face[d]; face[d] = face[c]; face[c] = face[b];
        face[b] = face[a]; face[a] = t;
    }
    friend ostream& operator<<(ostream& os, const Dice d) {
        os << "[";                          // U, B, L, F, R, D
        for (int i = 0; i < 6; i++) os << d[i] << " ]"[i == 5];
        return os;
    }
};

int main() {
    Dice dice;
    vector<Dice> all_rolls = dice.all_rolls();
    int n;
    while (cin >> n, n) {
        int cnt = 0;
        set<string> s;
        while (n--) {
            string cur, t;
            for (int i = 0; i < 6; i++) cin >> t, cur += t[0];
            swap(cur[3], cur[4]);
            if (s.count(cur)) {
                cnt++;
            } else {
                swap(cur[3], cur[4]);
                for (Dice &dice: all_rolls) {
                    string t;
                    for (int i = 0; i < 6; i++) t += cur[dice[i]];
                    s.emplace(t);
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {
	  
	public static void main(String args[]) {
		    Scanner scanner = new Scanner(System.in);
		    
		    int a = scanner.nextInt();
		    int b = scanner.nextInt();
		    int h = scanner.nextInt();
		    
		    System.out.println((a+b)*h/2);
		    
		    scanner.close(); }
		  }

Measured memory_bytes: 21588
#a = int(input())
#b,c = map(int,input().split())
#s = input()
#list_s = list(input())
#list_int = list(map(int,input().split()))

#list = [0 for i in range(n)]
#dp = [[0 for i in range(A)] for j in range(B)]

#list_int 並べて出力 print (' '.join(map(str,ans_li)))
#list_str 並べて出力 print (' '.join(list))

# 2進数 format(10, 'b') # '1010'

# aa=[int(input()) for i in range(n)]

#for i,name in enumerate(list)

''' 二次元配列を一列ずつ
for i in ans:
	print(*i)
'''
''' heapq
queue = []
heapq.heapify(queue) #heapqの作成
heapq.heappush(queue,num) #numのpush(値の追加)
pop = heapq.heappop(queue) #numのpop(最小値の出力)
pop = heapq.heappushpop(queue,num) #push -> pop

'''

from collections import defaultdict
import sys,heapq,bisect,math,itertools,string
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7


ar = list(map(int,input().split()))
print(max(ar)-min(ar))


Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(){
  int W, H, N, menseki = 0;
  int x[110], y[110], a[110], check[110][110];

  cin >> W >> H >> N;
  for(int i = 0; i < N; i++){
    cin >> x[i] >> y[i] >> a[i];
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      check[i][j] = 0;
    }
  }

  for(int i = 0; i < N; i++){
    switch (a[i]) {
      case 1:
      for(int q = 0; q < x[i]; q++){
        for(int p = 0; p < H; p++){
          check[p][q] = 1;
        }
      }

      break;

      case 2:
      for(int q = x[i]; q < W; q++){
        for(int p = 0; p < H; p++){
          check[p][q] = 1;
        }
      }

      break;

      case 3:
      for(int q = 0; q < W; q++){
        for(int p = 0; p < y[i]; p++){
          check[p][q] = 1;
        }
      }

      break;

      case 4:
      for(int q = 0; q < W; q++){
        for(int p = y[i]; p < H; p++){
          check[p][q] = 1;
        }
      }

      break;

    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      menseki += check[i][j];
    }
  }
  
  menseki = W*H - menseki;

  cout << menseki << endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  ll t,a;cin>>t>>a;
  vector<ll> h(n);
  vector<double> ans(n);
    
  rep(i,n){
    cin>>h[i];
    ans[i]=abs(double(1.0*a-1.0*t+h[i]*0.006));
  }
  auto minIt = min_element(all(ans));
  size_t minIndex = distance(ans.begin(), minIt);
  cout<<minIndex+1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100001
int main(){
  int A[MAX];
  int n,i,x,temp,j,temp2,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  x=A[n];
  j=0;
  for(i=1;i<n;i++){
    if(A[i]<=x){
      j=j+1;
      temp=A[j];
      A[j]=A[i];
      A[i]=temp;
    }
  }
      temp2=A[n];
      A[n]=A[j+1];
      A[j+1]=temp2;   
    
  
 
    for(k=1;k<=n;k++){
      if(k==n){
	printf("%d\n",A[k]);
      }
      else if(k==j+1){
	printf("[%d] ",A[k]);
      }
      else printf("%d ",A[k]);

    }
    return 0;
  
}



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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#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 pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	string s;
	string ans = "";
	cin >> s;
	REP(i,s.size()){
		if(s[i] == '0'){
			ans = (ans + "0");
		}else if(s[i] == '1'){
			ans = (ans + "1");
		}else if(s[i] == 'B'){
			if(ans != ""){
				ans = ans.substr(0,ans.size()-1);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;
  int i, j, k;
  int b, f, r, v;
  int arr[4][3][10];

  // array initialization
  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
	arr[i][j][k] = 0;
      }
    }
  }

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d %d %d %d", &b, &f, &r, &v);
    arr[b - 1][f - 1][r - 1] += v;
  }

  for(i = 0; i < 4; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 10; k++){
	printf(" %d", arr[i][j][k]);
      }
      printf("\n");
    }
    if(i != 3){
      printf("####################\n");
    }
  }

  return 0;
}


Measured memory_bytes: 2088
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

//  ABC051 C - Back and Forth
// 2020.06.14

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;
  string ans;
  // (1)
  int sx1 = sx, sy1 = sy+1, tx1 = tx-1, ty1 = ty;
  ans += "U";
  REP(i, ty1-sy1){
    ans += "U";
  }
  REP(i, tx1-sx1){
    ans += "R";
  }
  ans += "R";

  // (2)
  int sx2 = sx+1, sy2 = sy, tx2 = tx, ty2 = ty-1;
  ans += "D";
  REP(i, ty2-sy2){
    ans += "D";
  }
  REP(i, tx2-sx2){
    ans += "L";
  }
  ans += "L";

  // (3)
  int sx3 = sx, sy3 = sy-1, tx3 = tx+1, ty3 = ty;
  ans += "D";
  REP(i, tx3-sx3){
    ans += "R";
  }
  REP(i, ty3-sy3){
    ans += "U";
  }
  ans += "L";

  // (4)
  int sx4 = sx-1, sy4 = sy, tx4 = tx, ty4 = ty+1;
  ans += "U";
  REP(i, tx4-sx4){
    ans += "L";
  }
  REP(i, ty4-sy4){
    ans += "D";
  }
  ans += "R";

  cout << ans << endl;
}

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

vector<P> dp(10020,make_pair(-1000000,0));
int main(){
    int n,m;
    cin >> n >> m;
    vector<int> vec={0,2,5,5,4,5,6,3,7,6};
    vector<int> a(m);
    rp(i,m) cin >> a.at(i);
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());
    dp[0]=make_pair(0,0);
    for(int i=1; i<=n; i++){
        rp(j,m){
            if(i-vec[a.at(j)]>=0){
                if(dp[i]<make_pair(dp[i-vec[a.at(j)]].first+1,a.at(j))){
                    dp[i]=make_pair(dp[i-vec[a.at(j)]].first+1,a.at(j));
                }
            }
        }
    }
    int digit=dp[n].first;
    rp(i,digit){
        cout << dp[n].second;
        n-=vec[dp[n].second];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, a[SIZE];

  scanf("%d", &n);

  for(int i=0;i<n;i++){
    scanf("%d", a+i);
    a[i] -= i + 1;
  }

  sort(a, a+n);

  ll ans = 0;

  for(int i=0;i<n;i++){
    ans += abs(a[i] - a[n/2]);
  }

  printf("%lld\n", ans);
  
  return 0;
}



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

using namespace std;

int main()
{
    int N;
    cin>>N;
    int NT = N;
    int pom = 1;
    long long suma=0;
    bool czy=true;
    while(N/=10)
    {
        pom*=10;
        if(czy)
        {
            suma+=pom-pom/10;
        }
        czy=!czy;
    }
    if(czy)suma+=NT-pom+1;
    cout<<suma;
}


Measured memory_bytes: 256
val MOD = 998244353

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val dd = readLine()!!.split(" ").map{it.toInt()}

    if (dd[0] != 0) {
        println(0)
        return
    }

    val groups = mutableMapOf<Int, Int>()
    var max = 0
    dd.forEach {
        groups[it] = (groups[it] ?: 0) + 1
        if (it > max) max = it
    }

    if (groups[0]!! > 1) {
        println(0)
        return
    }

    var sum = 1L
    for (i in max downTo 1) {
        val cnt = groups[i] ?: 0
        val nextCnt = groups[i-1] ?: 0
        if (cnt == 0 || nextCnt == 0) {
            println(0)
            return
        }

        sum *= modPow(nextCnt, cnt)
        sum %= MOD
    }

    println(sum % MOD)
}

fun modPow(base: Int, pow: Int): Long {
    var ans = 1L
    repeat(pow) {
        ans *= base
        ans %= MOD
    }
    return ans
}

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

static const int MAX = 100;
static const long long INFTY = ( 1LL << 32 );

int n;
long long d[MAX][MAX];

void floyd() {
	for(int k = 0; k < n; k++) {
		for(int i = 0; i < n; i++) {
			if(d[i][k] == INFTY) continue;
			for(int j =0; j < n; j++) {
				if(d[k][j] == INFTY) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}


int main() {
	int u, v, e, c;
	cin >> n >> e;
	
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			d[i][j] = ((i == j) ? 0 : INFTY);
		}
	} 
	
	for(int i = 0; i < e; i++) {
		cin >> u >> v >> c;
		d[u][v] = c;
	}
	
	floyd();
	
	bool negative = false;
	for(int i = 0; i < n; i++) {
		if(d[i][i] < 0) negative = 1; 
	}
	
	if(negative) {
		cout << "NEGATIVE CYCLE" << endl;
	} else {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < n; j++) {
				if(j > 0) cout << " ";
				if(d[i][j] == INFTY) cout << "INF";
				else cout << d[i][j];
			}
			cout << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

void solve(int w,int h) {
    int n;
    cin >> n;
    
    vector<pair<int,int> > x,y;

    for(int i=0; i<n; ++i) {
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        x.push_back(make_pair(a,i));
        x.push_back(make_pair(c,i));
        y.push_back(make_pair(b,i));
        y.push_back(make_pair(d,i));
    }

    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    int prev=0;
    int rnkx=0;
    bool lc;
    if(x[2*n-1].first==w) lc=true;
    else lc=false;
    for(int i=0; i<2*n; ++i) {
        if(prev!=x[i].first) rnkx+=2;
        prev=x[i].first; x[i].first=rnkx;
    }
    if(!lc) rnkx+=2;

    prev=0;
    int rnky=0;
    if(y[2*n-1].first==h) lc=true;
    else lc=false;
    for(int i=0; i<2*n; ++i) {
        if(prev!=y[i].first) rnky+=2;
        prev=y[i].first; y[i].first=rnky;
    }
    if(!lc) rnky+=2;

    sort(x.begin(),x.end(),[](pair<int,int>& lhs, pair<int,int>& rhs) {
        return (lhs.second==rhs.second?lhs.first<rhs.first:lhs.second<rhs.second);
    });
    sort(y.begin(),y.end(),[](pair<int,int>& lhs, pair<int,int>& rhs) {
        return (lhs.second==rhs.second?lhs.first<rhs.first:lhs.second<rhs.second);
    });

    vector<vector<int> > mp;
    vector<int> vtemp(rnkx+1,0);
    for(int i=0; i<rnky+1; ++i) mp.push_back(vtemp);

    for(int i=0; i<n; ++i) {
        for(int j=y[2*i].first; j<=y[2*i+1].first; ++j) {
            for(int k=x[2*i].first; k<=x[2*i+1].first; ++k) {
                mp[j][k]=-1;
            }
        }
    }

    int col=0;
    int dx[4]={0,1,0,-1};
    int dy[4]={1,0,-1,0};
    queue<pair<int,int> > q;
    for(int i=0; i<rnky+1; ++i) {
        for(int j=0; j<rnkx+1; ++j) {
            if(mp[i][j]!=0) continue;
            mp[i][j]=++col;
            q.push(make_pair(i,j));
            while(!q.empty()) {
                pair<int,int> p=q.front(); q.pop();
                int pj=p.second;
                int pi=p.first;
                for(int k=0; k<4; ++k) {
                    if(pi+dy[k]>=0 && pi+dy[k]<rnky+1 && pj+dx[k]>=0 && pj+dx[k]<rnkx+1
                        && mp[pi+dy[k]][pj+dx[k]]==0) {
                            mp[pi+dy[k]][pj+dx[k]]=mp[pi][pj];
                            q.push(make_pair(pi+dy[k],pj+dx[k]));
                    }
                }
            }
        }
    }
    cout << col << endl;

    return;
}


int main() {
    int w,h;
    while(true) {
        cin >> w >> h;
        if(w==0 && h==0) break;
        solve(w,h);
    }
    return 0;
}


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  cout<<a[0]<<a[1]<<a[2]<<a[3]<<' '<<a[4]<<a[5]<<a[6]<<a[7]<<a[8]<<a[9]<<a
  [10]<<a[11]<<'\n';
  return 0;
}

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

using namespace std;

string s[8];

int main() {
    int h, w; scanf("%d %d", &h, &w);
    for(int i = 0; i<h; ++i) cin >> s[i];
    if( s[0][0] != '#' || s[h-1][w-1] != '#' ) {
        puts("Impossible");
        return 0;
    }
    vector<int> prv;
    for(int i = 0; i<h; ++i) if( s[i][0] == '#' ) prv.push_back(i);
    for(int j = 1; j<w; ++j) {
        vector<int> now;
        for(int i = 0; i<h; ++i) if( s[i][j] == '#' ) now.push_back(i);
        if( prv.back() != now.front() ) {
            puts("Impossible");
            return 0;
        }
        prv = now;
    }
    puts("Possible");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S,T;cin>>S>>T;
    string ans;
    for(int i=0;i<N;i++){
        ans+=S[i];
        ans+=T[i];
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod (1000000007)
#define mul(a,b) (((a%mod)*(b%mod))%mod)
long frac(long x){
  if(x==1)return 1;
  return mul(x,frac(x-1));
}
int main(){
  long n,m,res;
  cin>>n>>m;
  if(n<m)swap(n,m);
  res=mul(frac(n),frac(m));
  if(n==m)res=mul(res,2);
  else if(n-1!=m)res=0;
  cout<<res;
  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        String str = scan.next();

        int max = 0;

        for(int i = 1; i < n; i++){
            String str1 = str.substring(0, i);
            String str2 = str.substring(i, n);
            
            int comp = agreement(str1, str2);
            if(comp > max)
                max = comp;
        }

        System.out.println(max);
    }

    public static int agreement(String s1, String s2){
        int cnt = 0;
        int[] record = new int[26];

        for(int i = 0; i < s1.length(); i++){
            for(int j = 0; j < s2.length(); j++){
                if(record[s1.charAt(i) - 'a'] == 0){
                    if(s1.charAt(i) == s2.charAt(j)){
                        record[s1.charAt(i) - 'a']++;
                        cnt++;
                        break;
                    }
                }
                else
                    break;
            }
        }
        
        return cnt;
    }  
}

Measured memory_bytes: 21972