akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int N, W;
vector<ll> w(110);
vector<ll> v(110);
vector<vector<ll>> dp(110, vector<ll>(100010, INFL));

int main(void){
	cin >> N >> W;
	for(int i = 0; i < N; i++) cin >> w[i] >> v[i];
	dp[0][0] = 0;
	for(int i = 1; i <= N; i++){
		for(int j = 0; j < 100010; j++){
			if(j-v[i-1] >= 0){
				dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1]);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < 100010; i++){
		if(dp[N][i] <= W){
			ans = i;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 87296
#include<iostream>


bool is_range(int a, int b, int c) {
  if (a < b and b < c) {
    return true;
  } else {
    return false;
  }
}


int main() {
  int a, b, c;

  std::cin >> a >> b >> c;
  std::string ans = is_range(a, b, c) ? "Yes" : "No";
  std::cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 3160
#include <iostream>
using namespace std;
int n,cnt;
string s;
string temp1,temp2,temp3;
string train[1000];
bool flag;
string reverse(string b){
	//cout << b<<endl;
	string a=b;
	for(int i=0;i<b.size();i++){
		a[i]=b[b.size()-1-i];
	}
	//cout << a<<endl;
	return a;
}

void check(string traintemp){
	flag=true;
	for(int i=0;i<cnt;i++){
		if(train[i]==traintemp)flag=false;
	}
	if(flag){
		train[cnt]=traintemp;
		cnt++;
	}
}
int main(){
	cin >>n;
	for(int i=0;i<n;i++){
		cin  >>s;
		cnt=1;
		train[0]=s;
		for(int j=1;j<s.size();j++){
			temp1=s.substr(0,j);
			temp2=s.substr(j);
			for(int k=1;k<=4;k++){
				temp3=temp1+temp2;
				//cout << temp3<<endl;
				check(temp3);
				temp3=temp2+temp1;
				check(temp3);
				temp2=reverse(temp2);
				if(k==2)temp1=reverse(temp1);
				//cout << temp3<<endl;
			}
		}
		cout << cnt<<endl;
	}
}

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

vector<int> g[100010];
map<int, long> cost[100010];
long d[100010];
const long inf=1L<<62;
int n;

void dijkstra(int s)
{
    fill(d, d+n, inf);
    d[s]=0;

    typedef pair<long, int> P;
    priority_queue<P, vector<P>, greater<P>> q;
    q.emplace(0, s);

    while (!q.empty()) {
        auto p=q.top();
        q.pop();
        auto v=p.second;
        auto c=p.first;
        if (d[v]<c) continue;
        for(int u: g[v]) {
            if (d[u]>d[v]+cost[v][u]) {
                d[u]=d[v]+cost[v][u];
                q.emplace(d[u], u);
            }
        }
    }
}

int main()
{
    cin>>n;
    for(int i=0; i<n-1; ++i) {
        int a, b, c;
        cin>>a>>b>>c;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
        cost[a][b]=cost[b][a]=c;
    }

    int q, k; cin>>q>>k;
    --k;
    dijkstra(k);

    while (q--) {
        int x, y; cin>>x>>y;
        --x, --y;
        cout<<d[x]+d[y]<<endl;
    }
}


Measured memory_bytes: 26228
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
vector<int> pos[15];
int main(){
  int n,d;
  cin>>n>>d;
  for(int i=0;i<n;i++){
    for(int j=0;j<d;j++){
      int k;
      cin>>k;
      pos[i].push_back(k);
    }
  }
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      int sk=0;
      for(int k=0;k<d;k++){
        sk+=(pos[i][k]-pos[j][k])*(pos[i][k]-pos[j][k]);
      }
      if((int)sqrt(sk)*(int)sqrt(sk)==sk) ans++;
    }
  }
  cout<<ans<<endl;
}


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

#define PB          push_back
#define PF          push_front
#define MP          make_pair
#define FI          first
#define SE          second
#define SIZE( A )   int( ( A ).size( ) )
#define ALL( A )    ( A ).begin( ), ( A ).end( )
#define ALLR( A )   ( A ).rbegin( ), ( A ).rend( )

using namespace std;

typedef long long           ll;
typedef unsigned long long  ull;
typedef long double         lf;
typedef pair< int, int >    pii;
typedef pair< ll, ll >      pll;
typedef vector< bool >      vb;
typedef vector< lf >        vd;
typedef vector< ll >        vll;
typedef vector< int >       vi;
typedef vector< pii >       vpii;

const int MAXN = int( 1e5 )+10;
const int MOD  = int( 360 );
const int oo   = INT_MAX;

int n;
int arr[ MAXN ];

int main( ) {

  #ifdef LOCAL
    freopen( "input", "r", stdin );
    //freopen( "output", "w", stdout );
  #else
    //freopen( "attack.in", "r", stdin );
    //freopen( "attack.out", "w", stdout );
    ios_base::sync_with_stdio( 0 );
    cin.tie( 0 );
  #endif
  while( cin >> n ) {
    for( int i = 0; i < n; ++i )
      cin >> arr[ i ];
    ll ans = 0;
    for( int i = 0; i < n; ++i ) {
      ans += arr[ i ]/2;
      arr[ i ] %= 2;
      if( i+1 < n && arr[ i ] && arr[ i+1 ] ) {
        ans++;
        arr[ i+1 ]--;
      }
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 640
#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iostream>
#include<string>
using namespace std;

int main(){

    string s;

    cin>>s;

    // cout<<s.at(s.length() - 1)<<endl;

    if(s.at(s.length() - 1) == 's'){
        // cout<<s.substr(0, s.length() - 1)<<"es"<<endl;
        cout<<s<<"es"<<endl;
    }
    else{
        cout<<s<<'s'<<endl;
    }


    return 0;
}

Measured memory_bytes: 3624
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n, m, q;
    cin >> n >> m >> q;
    yukari<int> qs(q, akari<int>(4));
    for (auto &qq : qs)
    {
        for (int i = 0; i < 4; i++)
        {
            cin >> qq[i];
        }
    }
    i64 ans = 0;
    auto dfs = [&](auto &&self, akari<int> a, int i) -> void {
        if (i == n + 1)
        {
            i64 res = 0;
            for (auto &qq : qs)
            {
                if (a[qq[1]] - a[qq[0]] == qq[2])
                {
                    res += qq[3];
                }
            }
            //print(res);
            ans = max(ans, res);
            return;
        }
        auto b(a);
        for (int j = b.back(); j <= m; j++)
        {
            b.push_back(j);
            self(self, b, i + 1);
            b.pop_back();
        }
    };
    dfs(dfs, {1}, 0);
    cout << ans << endl;
}

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


Measured memory_bytes: 3612
num = int(input())
taro, hanako = 0 ,0
for i in range(num):
    lst = list(map(str, input().split()))
    while 1:
        if lst[0] == lst[1]:
            taro = taro + 1
            hanako = hanako + 1
            break
        else:
            length = min(len(lst[0]),len(lst[1]))
            for j in range(length):
                first = ord(lst[0][j:j+1])
                second = ord(lst[1][j:j+1])
                if first > second:
                    taro = taro + 3
                    break
                elif first < second:
                    hanako = hanako + 3
                    break
                elif j == length - 1:
                    if len(lst[0]) > len(lst[1]):
                        taro = taro + 3
                    elif len(lst[0]) < len(lst[1]):
                        hanako = hanako + 3
                    break
            break
print(str(taro) + " " + str(hanako))


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

using namespace std;
using   ll=long long;

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

#define endl            "\n"
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define int             long long int
#define pll                pair<int , int>

#define ALL(v)          v.begin(),v.end()
#define ALLR(v)         v.rbegin(),v.rend()
#define pii             3.14159265358979323
#define inf             LLONG_MAX
#define ones(x)         __builtin_popcount(x)
#define fill(a,b)       memset(a,b,sizeof(a))
#define mod             1000000007
#define hell            998244353

ll mod_pow(ll a,ll b,ll m)
{
    ll res = 1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a)
{
    return mod_pow(a , mod-2 , mod);
}

const int maxn = 1e6 + 5;

map<int,int> f;

int ok = 1;

map<int,int> jj;

int vis[maxn];

void go() 
{
	for(int i = 2; i < maxn; ++i) {
		if(!vis[i]) {
			for(int j = i; j < maxn; j += i) {
				if(f[j] > 0) {
					jj[i] += f[j];
					
					if(jj[i] > 1) {
						ok = 0;
						break;
					}
				}
				
				vis[j] = 1;
			}
		}
		
		if(ok == 0) {
			break;
		}
	}
}

void solve()
{
	int n;
	
	cin >> n;
	
	int a[n];
	
	int g = 0;
	
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
		
		f[a[i]]++;
		
		g = __gcd(g , a[i]);
	}
	
	go();
	
	if(ok) {
		cout << "pairwise coprime";
	}
	else {
		if(g == 1) {
			cout << "setwise coprime";
		}
		else {
			cout << "not coprime";
		}
	}
}

signed main() {
    fast;

    int t = 1;
   
    //cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 81736
import itertools
N=int(input())
l=len(str(N))
s=set()
S='753'
for i in range(1,l+1):
    for j in itertools.product(S,repeat=i):
        s.add(int(''.join(j)))
li=sorted(s)
cnt=0
for i in range(len(li)):
    if(li[i]>N):
        break
    if('7' in str(li[i]) and '5' in str(li[i]) and '3' in str(li[i])):
        cnt+=1
print(cnt)

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

using namespace std;

long long a, b, c, d;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> a >> b;
	c = __gcd(a, b);
	d = a*b/c;
	cout << d << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<int> row[2005],col[2005];
int main(){
	int h,w,i,j;
	cin>>h>>w;
	for(i=0;i<h;++i) row[i].push_back(-1);
	for(i=0;i<w;++i) col[i].push_back(-1);
	 
	for(i=0;i<h;++i){
		for(j=0;j<w;++j){
			char x;
			cin>>x;
			if(x=='#'){
				row[i].push_back(j);
				col[j].push_back(i);
			}
		}
	}


	for(i=0;i<h;++i) row[i].push_back(w);
	for(i=0;i<w;++i) col[i].push_back(h);
	 
	int ans=1;
	for(i=0;i<h;++i){
		for(j=0;j<w;++j){
			int cnt=0;
			int left=lower_bound(row[i].begin(), row[i].end(), j) - row[i].begin();
			int right=lower_bound(row[i].begin(), row[i].end(), j) - row[i].begin();
			int up=lower_bound(col[j].begin(), col[j].end(), i) - col[j].begin();
			int down=lower_bound(col[j].begin(), col[j].end(), i) - col[j].begin();
			if(col[j][up]==i || row[i][left]==j) continue;
			--left;
			--up;
			cnt+=i-col[j][up]-1;
			cnt+=col[j][down]-i-1;
			cnt+=j-row[i][left]-1;
			cnt+=row[i][right]-j-1;
			ans=max(ans,cnt+1);
		}
	}

	cout<<ans;
	return 0;
}

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

int N, K, X, Ans;

int f(int l) { return (l+K-1) / K; }

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> K; K--; Ans = N;
	for(int i = 1, c; i <= N; i++) {
		cin >> c;
		if(1 == c) X = i;
	}

	for(int i = max(1, X-K), e = min(N, X+K); i <= e; i++) {
		if(N < i+K) break;
		int t = 1 + f(i-1) + f(N-K-i);
		if(t < Ans) Ans = t;
	}

	cout << Ans << endl;
	return 0;
}

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

#define MAX_N 1010
#define pb push_back

int main(){
  int N, M;
  
  while(cin >> N >> M){
    if(N == 0 && M == 0) break;
    vector<int> P(N), P2;

    for(int i = 0 ; i < N ; i++){
      cin >> P[i];
      P2.pb(P[i]);
    }

    P2.pb(0);
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < N ; j++){
	P2.pb(P[i]+P[j]);
      }
    }

    sort(P2.begin(), P2.end());
    
    int ans = 0;
    for(int i = 0 ; i < P2.size() ; i++){
      if(M >= P2[i]){
	vector<int>::iterator it = upper_bound(P2.begin(), P2.end(), M-P2[i]);
	it--;
	ans = max(ans, P2[i]+ *it);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 9188
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 100005;
int partition(int arr[], int p, int r)	//[p, r)????????????,????????????pivot??????
{
	int pivot = arr[r - 1];
	int i = p;
	for (int j = p; j < r - 1; ++j)
	{
		if (arr[j] <= pivot)
		{
			swap(arr[i++], arr[j]);
		}
	}
	swap(arr[i], arr[r - 1]);
	return i;
}

int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	int arr[N];
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> arr[i];
	int idx = partition(arr, 0, n);
	for (int i = 0; i < idx; ++i)
	{
		if (i > 0)
			cout << ' ';
		cout << arr[i];
	}
	cout << ' ' << '[' << arr[idx] << ']';
	for (int i = idx + 1; i < n; ++i)
		cout << ' ' << arr[i];
	cout << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, M, K; cin >> N >> M >> K;
  string ans = "No";
  for(int i = 0; i <= N; ++i) {
    for(int k = 0; k <= M; ++k) {
      ll tmp = M * i + N * k - 2 * i * k;
      if(tmp == K) {
        ans = "Yes";
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    PriorityQueue<Dish> q = new PriorityQueue<>((a, b)->b.sum-a.sum);
    for (int i= 0; i < N; i++) {
      int A = sc.nextInt();
      int B = sc.nextInt();
      q.offer(new Dish(A, B));
    }
    int t = 0;
    long ans = 0;
    while (!q.isEmpty()) {
      Dish d = q.poll();
      if (t%2 == 0) {
        ans += d.a;
      } else {
        ans -= d.b;
      }
      t++;
    }
    
    System.out.println(ans);
  }
  private static class Dish {
    final int a;
    final int b;
    final int sum;
    Dish(int a, int b) {
      this.a = a;
      this.b = b;
      this.sum = a+b;
    }
  }
}

Measured memory_bytes: 66320
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int[][] a = new int[3][3];
    for(int i = 0;i < 3;i++){
      for(int x = 0;x < 3;x++){
        a[i][x] = sc.nextInt();
      }
    }
    boolean[][] flag = new boolean[3][3];
    boolean ans = false;
    int n = sc.nextInt();
    int[] b = new int[n];
    for(int j = 0;j < n;j++){
      b[j] = sc.nextInt();
    }
    for(int y = 0;y < 3;y++){
      for(int z = 0;z < 3;z++){
        for(int c = 0;c < n;c++){
          if(a[y][z] == b[c]){
            flag[y][z] = true;
          }
        }
      }
    }
    for(int p = 0;p < 3;p++){
      if(flag[p][0] == true && flag[p][1] == true && flag[p][2] == true) ans = true;
      if(flag[0][p] == true && flag[1][p] == true && flag[2][p] == true) ans = true;
    }
    if(flag[0][0] == true && flag[1][1] == true && flag[2][2] == true)
      ans = true;
    if(flag[0][2] == true && flag[1][1] == true && flag[2][0] == true)
      ans = true;
    if(ans){
      System.out.println("Yes");        
    }else{
      System.out.println("No");        
    }
  }
}

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

int main () {
#ifdef _test
    freopen( "in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    while (n!=0) {
        int r = n%10;
        if ( r==2 || r==4 || r==5 || r==7 || r==9) {
            cout << "hon" << '\n';
            return 0;
        }
        if (r==0|| r==1 || r==6 || r==8) {
            cout << "pon" << '\n';
            return 0;
        }
        if ( r==3) {
            cout << "bon" << '\n';
            return 0;
        }
        r/=10;
    }
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
using namespace std;
int main(){
 string s;
 int y,m,d;
 cin >> s;
 y=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
 m=(s[5]-'0')*10+(s[6]-'0');
 d=(s[8]-'0')*10+(s[9]-'0');
 if(y<2019) cout << "Heisei"<<endl;
 else if(y>2019) cout << "TBD"<<endl;
 else{
   if(m<4) cout << "Heisei"<<endl;
   else if(m>4) cout << "TBD"<<endl;
   else{
     if(d<=30) cout << "Heisei"<<endl;
     else cout <<"TBD"<<endl;
   }
 }
}


Measured memory_bytes: 256
#include"iostream"
using namespace std;
int main()
{
  int a,b,c;
  int n;
  cin>>n;
  c=1;
  a=1;b=1;
  for(int i=1;i<n;i++)
    {
      c=a+b;
      a=b;
      b=c;
    }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(void) {
    int N, C;
    vector<int> A;
    map<int,int> M;
    cin >> N;
    for (int i=0;i<N;i++) {
        int x;
        cin >> x;
        A.push_back(x);
    }
    C = 0;
    for (int i=0;i<N;i++) {
        if (M.find(A[i]) != M.end()) M[A[i]]++;
        else M[A[i]] = 1;
    }
    for (auto itr=M.begin(); itr != M.end(); itr++) {
        if (itr->second % 2) C++;
    }
    cout << C << endl;

    return 0;
}

Measured memory_bytes: 5368
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef pair<int, int> P;

int h, w, ans;
int castle[1001][1001], times[1001][1001];
int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
char beach[1001][1001];

int main(){
    scanf("%d%d", &h, &w);
    for(int i = 0; i < h; i++){
        scanf("%s", &beach[i]);
    }

    queue<P> Q;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(beach[i][j] == '.'){
                Q.push(P(i, j));
            } else{
                castle[i][j] = (int)beach[i][j] - 48;
            }
        }
    }

    while(Q.size()){
        P p = Q.front();
        Q.pop();
        ans = max(ans, times[p.first][p.second]);

        for(int i = 0; i < 8; i++){
            int y = p.first + dy[i], x = p.second + dx[i];
            if(y < 0 || y >= h || x < 0 || x >= w){
                continue;
            }

            castle[y][x]--;
            if(castle[y][x] == 0){
                Q.push(P(y, x));
                times[y][x] = times[p.first][p.second] + 1;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 10044
#include <cstdio>
#include <cstring>
#define ll long long

ll n,m;
char s[100010],t[100010];
ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}

int main()
{
	scanf("%lld %lld",&n,&m);
	scanf("%s %s",s+1,t+1);
	ll lcm=n/gcd(n,m)*m;
	ll a=lcm/n,b=lcm/m;
	ll Gcd=a/gcd(a,b)*b;
	ll c=Gcd/a,d=Gcd/b;
	ll x=0,y=0;
	while(x+1<=n&&y+1<=m)
	{
		if(s[x+1]!=t[y+1])
		{
			printf("-1");
			return 0;
		}
		x+=c;
		y+=d;
	}
	printf("%lld",lcm);
}

Measured memory_bytes: 384
#include<stdio.h>
 
int main(){
  int x ,y ,max ,min ,newmax;
  scanf("%d %d" ,&x ,&y);

  if(x > y){
   max = x;
   min = y;
  }
  else{
   max = y;
   min = x;
  }
   while(max != min && min !=0){
    newmax = min;
    min = max % min;
    max = newmax;
  }
   	printf("%d\n" ,max);

 return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

int parK[200000];
int rank_K[200000];
int parL[200000];
int rank_L[200000];

void init(int n){
    for(int i=0;i<n;i++){
        parK[i]=i;
        rank_K[i]=0;
        parL[i]=i;
        rank_L[i]=0;
    }
}

int findK(int x){
    if(parK[x]==x){
        return x;
    }else{
        return parK[x]=findK(parK[x]);
    }
}

void uniteK(int x, int y){
    x=findK(x);
    y=findK(y);
    if(x==y)return;
    if(rank_K[x]<rank_K[y]){
        parK[x]=y;
    }else{
        parK[y]=x;
        if(rank_K[x]==rank_K[y]) rank_K[x]++;
    }
}

bool sameK(int x, int y){
    return findK(x)==findK(y);
}

int findL(int x){
    if(parL[x]==x){
        return x;
    }else{
        return parL[x]=findL(parL[x]);
    }
}

void uniteL(int x, int y){
    x=findL(x);
    y=findL(y);
    if(x==y)return;
    if(rank_L[x]<rank_L[y]){
        parL[x]=y;
    }else{
        parL[y]=x;
        if(rank_L[x]==rank_L[y]) rank_L[x]++;
    }
}

bool sameL(int x, int y){
    return findL(x)==findL(y);
}

typedef pair<int,int> P;
map<P,int> M;
int main(){
    int N,K,L;
    cin>>N>>K>>L;
    init(N);
    for(int i=0;i<K;i++){
        int p,q;
        cin>>p>>q;
        p--;q--;
        uniteK(p,q);
    }
    for(int i=0;i<L;i++){
        int r,s;
        cin>>r>>s;
        r--;s--;
        uniteL(r,s);
    }
    for(int i=0;i<N;i++){
        int k=findK(i);
        int l=findL(i);
        M[P(k,l)]++;
    }
    for(int i=0;i<N;i++){
        int k=findK(i);
        int l=findL(i);
        if(i)cout<<' ';
        cout<<M[P(k,l)];
    }
    cout<<endl;
}

Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S,T;
    cin >> S >> T;
    int ans = 0;
    int N = S.size();
    for (int i = 0; i < N; i++) {
      if(S.at(i) == T.at(i)){
          ans += 0;
      }
      else{
          ans += 1;
      }
      
    }
    cout << ans << endl; 
}


Measured memory_bytes: 3820
def dist(a,b,data)
  ((data[a][0]-data[b][0])**2+(data[a][1]-data[b][1])**2)**0.5
end
s=0.0
data=[];(n=gets.to_i).times{data<<gets.split.map(&:to_i)}
path=[*0..(n-1)].permutation(n).to_a
path.each{|a|
a.each_cons(2){|a,b|s+=dist(a,b,data)}
}
p s/path.size

Measured memory_bytes: 8828
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 0; i < ((n - 1) / 2) / 2; i++) {
        if (s[i] != s[((n - 1) / 2) - 1 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = (n + 3) / 2 - 1; i < ((n + 3) / 2 + n - 2) / 2; i++) {
        if (s[i] != s[(n + 3) / 2 + n - 2 - i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
using namespace std;
//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}
int main()
{
	ll n,k;
	cin>>n>>k;ll ans=n;
	if(n<k)
	{
		if(abs(n-k)<n)ans=abs(n-k);
	}
	else if(n>k)
	{
		ll cnt=n/k;
		n=n-(cnt*k);
		ans=n;
		if(abs(n-k)<n)ans=abs(n-k);
	}
	else ans=0;
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int s[10005];
void trip()
{
	for (int i=1;i<=10000;i++)
    {
    	int x,y,z,num=0;
    	for (x=1;x<=sqrt(i);x++)
		{
			if (x*x+3+2*x>i) break;
			for (y=1;y<=sqrt(i);y++)
			{
				if (x*x+y*y+x*y+1+x+y>i) break;
				for (z=1;z<=sqrt(i);z++)
				{
					if (x*x+y*y+z*z+x*y+y*z+x*z>i) break;
					if (x*x+y*y+z*z+x*y+y*z+x*z==i) num++;
				}
			}
		}
		s[i]=num;
	}
}

int main()
{
    int n;
    trip();
    while (~scanf("%d",&n))
    	for (int i=1;i<=n;i++) printf("%d\n",s[i]);
    return 0;
}


Measured memory_bytes: 3828
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	int ret=0;
	int cur=mod;
	for(int i=0;i<a;i++){
		int p;scanf("%d",&p);
		if(cur>p){
			ret++;
			cur=p;
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}


void solve()
{
  
  int n,m;
  cin >> n >> m;

  cout<<(n*(n-1))/2 + (m*(m-1))/2;  
}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long ll;
//////////////////////////////////////////////////////
int main(){
	ll N;scanf("%lld",&N);
	vector<ll> L;
	vector<ll> R;
	
	REP(i,N){
	    ll x,y; scanf("%lld%lld",&x,&y);
	    L.PB(x); R.PB(y);
	}
	
	ll ans = 0;
	ll npos = 0;
	ll lind = 0;
	ll rind = 0;
	ll turn = 1; // 1 --> Next left , -1 --> Next right
	
	sort(L.begin(),L.end(),greater<int>() ); // L - inascending
	sort(R.begin(),R.end());  // R - ascending
	
	while((lind < N) and (rind < N)){
	    if (turn == 0) break;
	    if (turn == 1){
	        ll s = R[rind];
	        if (s < npos){
	            turn = -1;
	            ans += (npos - s);
	            npos = s;
	            rind++;
	        }else{
	            turn = 0;
	        }
	    
	    }else{
	        ll s = L[lind];
	        if (npos < s){
	            turn = 1;
	            ans += (s - npos);
	            npos = s;
	            lind++;
	        }else{
	            turn = 0;
	        }
	        
	    }
	}
	
	ans += abs(npos);
    
	npos = 0;
	lind = 0;
	rind = 0;
	ll ans2 = 0;
	turn = -1;
	//reverse(L.begin(),L.end());
	//reverse(R.begin(),R.end());
	
	while((lind < N) and (rind < N)){
	    if (turn == 0) break;
	    if (turn == 1){
	        ll s = R[rind];
	        if (s < npos){
	            turn = -1;
	            ans2 += (npos - s);
	            npos = s;
	            rind++;
	        }else{
	            turn = 0;
	        }
	    
	    }else{
	        ll s = L[lind];
	        if (npos < s){
	            turn = 1;
	            ans2 += (s - npos);
	            npos = s;
	            lind++;
	        }else{
	            turn = 0;
	        }
	        
	    }
	}
	
	ans2 += abs(npos);
	
	PRINTLLD(max(ans,ans2));
	
	return 0;
}


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

using namespace std;

int main() {
	#if LOCAL
	freopen("b.in", "r", stdin);
	#endif
    int N,M,C;
	cin>>N>>M>>C;
    int res = 0;
    vector<int> B(M);
    for(int i=0;i<M;i++) {
        cin>>B[i];
    }
    for(int i=0;i<N;i++) {
        int a,sum = C;
        for(int j=0;j<M;j++) {
            cin>>a;
            sum+=a*B[j];
        }
        if(sum>0)res++;
    }
    cout<<res<<endl;

	return 0;
}

Measured memory_bytes: 256
from _collections import deque


def bfs(field, field_info, starting_y, starting_x, goal_y, goal_x):
    queue = deque([[starting_y, starting_x]])
    field_info[starting_y][starting_x] = 1

    while queue:
        y, x = queue.popleft()
        if [y, x] == [goal_y, goal_x]:
            return field_info[y][x]
        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + dy, x + dx
            if 0 <= new_y <= goal_y and 0 <= new_x <= goal_x and field[new_y][new_x] == "." and field_info[new_y][new_x] == -1:
                field_info[new_y][new_x] = field_info[y][x] + 1
                queue.append([new_y, new_x])


def solve():
    number_of_rows, number_of_columns = list(map(int, input().split()))  # Row, Column数
    field = [input() for _ in range(number_of_rows)]
    field_info = [[-1] * number_of_columns for _ in range(number_of_rows)]
    starting_y, starting_x = 0, 0
    goal_y, goal_x = number_of_rows - 1, number_of_columns - 1
    bfs(field, field_info, starting_y, starting_x, goal_y, goal_x)

    # # BFSの結果をチェック
    # for field_info_line in field_info:
    #     print(field_info_line)

    if field_info[goal_y][goal_x] == -1:
        print(-1)
        return
    else:   # 到達できる場合
        number_of_black_cell = 0
        for row_i in range(number_of_rows):
            for column_i in range(number_of_columns):
                if field[row_i][column_i] == "#":
                    number_of_black_cell += 1
        point = number_of_columns * number_of_rows - field_info[goal_y][goal_x] - number_of_black_cell
        print(point)

# ここで必要なチェックを行う
solve()

Measured memory_bytes: 40176
it = lambda: list(map(int, input().strip().split()))

def paint(G, H, W, a, b):
    ans = 0
    for i in range(H):
        if a & (1 << i):
            for j in range(W):
                if G[i][j] == '#' and b & (1 << j) == 0:
                    ans += 1
    return ans

def solve():
    ans = 0
    H, W, K = it()
    G = [input().strip() for _ in range(H)]
    for a in range(1 << H):
        for b in range(1 << W):
            if paint(G, H, W, a, b) == K:
                ans += 1
    return ans

if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 9212
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int a[200010];
int n;
long long ans;
int cnt;
bool f[200010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	if(a[1]!=0)
	{
		printf("-1");
		return 0;
	}
	for(int i=2;i<=n;i++)
	{
		if(a[i]>a[i-1]+1)
		{
			printf("-1");
			return 0;
		}
	}
	for(int i=n;i>=1;i--)
	{
		int d=n-i;
		if(f[d])cnt--;
		if(!a[i])continue;
		if(!f[a[i]+d])
		{
			cnt++;
			f[a[i]+d]=true;
		}
		ans+=cnt;
	}
	printf("%lld",ans);
	return 0;
} 

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

int main(){
    int n, i, c, t = 0;
    cin >> n;
    int v[n];
    for(i=0; i<n; i++){
        cin >> v[i];
    }
    for(i=0; i<n; i++){
        cin >> c;
        if(v[i]-c > 0){
            t += v[i]-c;
        }
    }
    cout << t;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int dp[1001][1001];
#define MOD 1000000007

int main(){
      int h, w;
      cin>>h>>w;
      memset(dp, 0, sizeof(dp));
      dp[0][1]=1;
      for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                  char a;
                  cin>>a;
                  
                  if(a=='.')
                        dp[i][j]=1;
                  else dp[i][j]=0;
            }
      }
      for(int i=1; i<=h; i++){
            for(int j=1; j<=w; j++){
                  if(dp[i][j]==1)dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
            }
      }
      cout<<dp[h][w]<<'\n';
}

Measured memory_bytes: 11460
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	cin>>s;
	cin>>t;
	int ans=0;
	for(int i=0;i<s.length();i++){
		if(s[i]==t[i]){
			ans++;
		}
	}
	cout<<ans;
	return 0;
} 

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

int main() {
 //vector<char> s;
 //vector<char> t;
  string s,t;
  cin >> s >> t;
  bool st = true;
  for(int i=0;i<t.size()-1;i++){
    if(s.at(i)!=t.at(i)){
      st = false;
      break;
    }
  }
  if(st){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
}

Measured memory_bytes: 3616
use proconio::input;

const MOD:i64 = 1_000_000_007;

fn main() {
    input!{
        k:usize,
        s:String,
    };

    let n = s.len();

    let mut ans:i64 = 0;

    let mut fact = vec![1i64;n+k+1];
    for i in 0..n+k {
        fact[i+1] = fact[i]*((i+1) as i64)%MOD;
    }

    let powm = |mut x,mut k| {
        let mut res = 1;
        while k>0 {
            if k&1==1 {
                res = res*x%MOD;
            }
            k>>=1;
            x=x*x%MOD;
        }
        res
    };
    let mod_inv = |x| {
        powm(x,MOD-2)
    };
    let comb = |n,k| {
        fact[n] * mod_inv(fact[n-k]) %MOD * mod_inv(fact[k])%MOD
    };
    for i in 0..k {
        let pat = comb(n+k-i-1,n-1)*powm(25,(k-i) as i64)%MOD*powm(26,i as i64)%MOD;
        ans+=pat;
        ans%=MOD;
    }
    ans+=powm(26,k as i64);
    ans%=MOD;

    println!("{}",ans);
    
    

    


}


Measured memory_bytes: 19608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;

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

	int n,m;
	cin >> n >> m;

	ll x[n];
	rep(i,n) cin >> x[i];

	ll y[m];
	rep(i,m) cin >> y[i];

	ll xsum = 0;
	FOR(k,1,n+1) {
		xsum += (k-1 - (n-k))*x[k-1];
		xsum %= MOD;
	}

	ll ysum = 0;
	FOR(k,1,m+1) {
		ysum += (k-1 - (m-k))*y[k-1];
		ysum %= MOD;
	}

	ll ans = xsum * ysum;
	ans %= MOD;

	cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
4
1 2 3 5

output:
30
"""

import sys
from functools import reduce


def gcd(x, y):
    if x < y:
        x, y = y, x

    while y > 0:
        r = x % y
        x = y
        y = r

    return x


def lcm(a, b):
    return a * b // gcd(a, b)


def solve(_n_list):
    return reduce(lcm, _n_list)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    cnt = int(_input[0])
    n_list = tuple(map(int, _input[1].split()))
    print(solve(n_list))

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

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

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

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

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


struct BIT {
    int sz;
    vector<int> tree;

    BIT(int n) {
        sz = n;
        tree.resize(n+1);
    }

    int sum(int i){
        int sm = 0;
        while (i > 0){
            sm += tree[i];
            i -= i & -i;
        }
        return sm;
    }

    int sum(int l, int r){
        return sum(r) - sum(l);
    }

    void add(int i, int x){
        while (i <= sz){
            tree[i] += x;
            i += i & -i;
        }
    }
};


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

    int N;
    cin >> N;
    string S;
    cin >> S;

//    auto st = BIT(N);
//    st.add(1, 1);
//    st.add(2, 2);
//    st.add(3, 4);
//    print(st.sum(1, 3));

    vector<BIT> treelist;
    REP(i, 26){
        treelist.emplace_back(BIT(N));
    }
    REP(i, N){
        char c = S[i];
        treelist[c-'a'].add(i+1, 1);
    }

    int Q;
    cin >> Q;
    REP(q, Q){
        int t;
        cin >> t;
        if (t == 1){
            int i;
            char c;
            cin >> i >> c;
            char origin = S[i-1];
            treelist[origin-'a'].add(i, -1);
            treelist[c-'a'].add(i, 1);
            S[i-1] = c;
        } else {
            int l, r;
            cin >> l >> r;
            int ans = 0;
            REP(c, 26){
                int sm = treelist[c].sum(l-1, r);
                if (sm > 0) {
                    ans++;
                }
            }
            print(ans);
        }
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll m,k;
  cin >> m >> k;
 ll pow=1;
  rep(i,0,m) pow*=2;
  if(k>=pow||(m==1&&k==1)) {
    cout << -1 << endl;
    return 0;
  }
  
  if(m==0) {
    cout << 0 << " " << 0 << endl;
    return 0;
  }
  if(m==1) {
    cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
    return 0;
  }
  
  rep(i,0,pow) if(i!=k) cout << i << " ";
  cout << k << " ";
  rep(i,0,pow) if(pow-1-i!=k) cout << pow-1-i << " ";
  cout << k << endl;
  
}


Measured memory_bytes: 1792
/*http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_A&lang=jp*/

#include <iostream>
#include <vector>

using namespace std;

int main(){
    int count=0;
    int n,q;
    vector<int> s;

    cin>>n;
    for (int i = 0; i < n; i++) {
        int tmp;
        cin>>tmp;
        s.push_back(tmp);
    }
    cin>>q;
    for (int i = 0; i < q; i++) {
        int tmp;
        cin>>tmp;
        for(int j:s) {
            if(j==tmp){
                count++;
                break;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1320
def palindrome(string): return 0 if string==string[::-1] else 1
stri = input()
s = list(stri)
a = len(s)//2
b = s[0:a]
c = s[a+1:]
d = palindrome(b)
e = palindrome(c)
f = palindrome(s)
if d==0 and e==0 and f==0:
    print('Yes')
else:
    print('No')

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  rep(i, n) if (s[i] != 'x') t += s[i];
  int m = t.size();
  rep(i, m / 2) {
    if (t[i] != t[m - i - 1]) {
      cout << -1 << endl;
      return;
    }
  }
  string h = t.substr(0, (m + 1) / 2);
  i64 ans = 0;
  int l = 0, r = n;
  for (int i = 0; i < h.size(); i++) {
    int tl = l;
    while (s[tl] == 'x') tl++;
    int tr = r;
    while (s[tr - 1] == 'x') tr--;
    ans += abs((tl - l) - (r - tr));
    l = tl + 1;
    r = tr - 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 592