akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		/*First ever A, last ever Z */
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		long A = I.nextLong();
		long B = I.nextLong();
		long C = I.nextLong();
		long D = I.nextLong();
		O.pln(max(A*B,C*D));
	}
	public static double max(double a, double b) {return Math.max(a, b);}
	public static double min(double a, double b) {return Math.min(a, b);}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static int min(int a, int b) {return Math.min(a,b);}
	public static int max(int a, int b) {return Math.max(a,b);}
	public static long abs(long x) {return Math.abs(x);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(min(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


Measured memory_bytes: 25596
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(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 debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int a, b; cin >> a >> b;
    if (a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int a[1000];

int main()
{
	int x,y;
	cin>>x>>y;
	a[1]=3;
	a[2]=2;
	a[3]=1;
	cout<<(a[x]+a[y])*100000+(x==1&&y==1 ? 400000:0)<<endl;
	return 0;
}

Measured memory_bytes: 764
import java.util.*;
 
class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	boolean f = false;
	for(int i = 1; i <= b; i++) {
		if((a * i) % b == c) {
			f = true;
			break;
		}
	}
	if(f == false) {
		System.out.println("NO");
	} else {
		System.out.println("YES");
	}
}
}

Measured memory_bytes: 21844
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, k = ril()
r, s, p = ril()
t = rs()

dic = {'r': p, 's': r, 'p': s}
ls = list(t)
lss = [ls[i::k] for i in range(k)]
res = 0
for ls in lss:
    prev = ls[0]
    res += dic[prev]
    for x in ls[1:]:
        if x != prev:
            res += dic[x]
            prev = x
        else:
            prev = None
print(res)

Measured memory_bytes: 12916
n = int(input())
s = list(input())
numcount = [0] * 10
ans = 0
for i in s:
    numcount[int(i)] += 1
for i in range(10):
    for j in range(10):
        for k in range(10):
            c = 0
            if numcount[i] == 0 or numcount[j] == 0 and numcount[k] == 0:
                continue
            elif ((i == j or i == k) and numcount[i] <= 1) or (j == k and numcount[j] <= 1):
                continue
            elif i == j == k and numcount[i] <= 2:
                continue
            else:
                c, l = 0, 0
                m = [i, j, k]
                while True:
                    if m[l] == int(s[c]):
                        l += 1
                    c += 1
                    if l == 3:
                        ans += 1
                        break
                    if c == n:
                        break
print(ans)

Measured memory_bytes: 44412
$N = <STDIN>;
@A = split(" ",<STDIN>);
@a_odd = ();
@a_even = ();
for(my $i = 0; $i < $#A + 1; $i++){
	if($i%2 == 0){
		push @a_even,$A[$i];
    }
    else{
		push @a_odd,$A[$i];
    }
}
sub mode_sort{
	my @list = @_;
    my %dup_hash;
    my @out_list;
    my @out_keys;
    for my $number(@list){
    	$dup_hash{$number}++;
    }
    
    for my $key (sort {$dup_hash{$b} <=> $dup_hash{$a}} keys %dup_hash) {
		push @out_list,$dup_hash{$key};
        push @out_keys,$key;
    }
    return (@out_keys,@out_list);
}

my @odd = &mode_sort(@a_odd);
my @even = &mode_sort(@a_even);

if($odd[0] != $even[0]){

    $first = $N/2 - $odd[($#odd+1)/2] + $N/2 - $even[($#even+1)/2];
	print $first;
    exit(0);
}
else{

    $first = $N/2 - $odd[($#odd+1)/2+1] +$N/2 - $even[($#even+1)/2];
    $second = $N/2 - $odd[($#odd+1)/2] +$N/2 - $even[($#even+1)/2+1];
    if($first <= $second){
    	print $first;
        exit(0);
    }
    else{
    	print $second;
        exit(0);
    }
}



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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int l[n*2];
	for(int i = 0; i < 2*n; i++)cin >> l[i];
	sort(l, l+2*n);
	ll ans = 0;
	for(int i = 0; i < n; i++)ans += l[i*2];
	cout << ans << endl;
    return 0;
}


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

int main() {
	int mt[10];
	int best[3]={-1, -1, -1};
	for(int i=0; i<10; ++i) {
		cin >> mt[i];
	}

	for(int i=0; i<10; ++i) {
		if(mt[i]>best[2]) {
			if(mt[i]>best[1]) {
				best[2]=best[1];
				if(mt[i]>best[0]) {
					best[1]=best[0];
					best[0]=mt[i];
				} else {
					best[1]=mt[i];
				}
			} else {
				best[2]=mt[i];
			}
		}
	}
	
	cout << best[0] << endl
		 << best[1] << endl
		 << best[2] << endl;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int N=1e5+5;

int n,a[N],ans=1e9,k;

inline int Get(int x,int y){
	if(x>=0) return y;
	if(y<=0) return -x;
	return y-x+min(y,-x);
}

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

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

int main() {
	int n, m, p, ans; vector<int> pv;
	while(1) {
		cin >> n >> m;
		if(!n&&!m) break;
		pv.clear(); ans = 0;
		for(int i=0; i<n; ++i) {
			cin >> p; pv.push_back(p);
		}
		sort(pv.begin(), pv.end(), greater<int>());
		for(int i=0; i<n; ++i) {
			if(i%m<m-1) ans += pv[i];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;





void solve(){
    int n, ans = 0;
    cin>>n;
    int a[n+5], b[n+5];
    ff(i,n-1)cin>>b[i];
    a[1] = b[1];
    for(int i = 2; i <= n - 1; i++)a[i] = min(b[i],b[i-1]);
    a[n] = b[n-1];
    ff(i,n)ans += a[i];
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf (int)(10000000)
using namespace std;

long long n;
vector<long long> a, b, now, num;
vector<vector<int>> dp;

long long solve();

int main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  for (auto& p : a) cin >> p;
  for (auto& p : b) cin >> p;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = (1LL << 51) - 2;
  for (int i = 50; i >= 0; --i) {
    dp.assign(51, vector<int>(51, 0));
    for (int j = 0; j <= 50; ++j) dp[j][j] = 1;
    for (int j = 0; j <= 50; ++j)
      for (int k = 1; k <= 50; ++k)
        if ((res >> k & 1) && i != k) dp[j][j % k] = 1;
    for (int l = 0; l <= 50; ++l)
      for (int j = 0; j <= 50; ++j)
        for (int k = 0; k <= 50; ++k) dp[j][k] |= dp[j][l] & dp[l][k];
    bool ch = 1;
    for (int j = 0; j < n; ++j)
      if (!dp[a[j]][b[j]]) ch = 0;
    if (ch && i) res -= 1LL << i;
    if (!ch && !i) return -1;
  }
  return res;
}


Measured memory_bytes: 3624
/*
ID: Sho10
LANG: C++
*/
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll a,b,c;
int32_t main(){
cin>>a>>b>>c;
swap(a,b);
swap(a,c);
cout<<a<<' '<<b<<' '<<c<<endl;
}



Measured memory_bytes: 764
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

int gcd(int max, int x) {
	if (x == 0)	return max;
	return gcd(x, max % x);
}

int main() {
	int N;
	cin >> N;

	int *x = (int*) malloc(sizeof(int*) * N + 1);
	cin >> x[0];

	for (int i = 1; i < N + 1; i++) {
		cin >> x[i];
	}

	sort(x, x + N + 1);

	vector<int> v;
	for (int i = 1; i < N + 1; i++) {
		v.push_back(x[i] - x[i - 1]);
	}

	int max = v[0];

	for (int i = 1; i < v.size(); i++) {
		max = gcd(max, v[i]);
	}

	cout << max << endl;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
#define endl "\n" 
#define ll long long 
#define sp " "
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	ll q=1;//cin>>q;
	while(q--){
		int n,l; cin>>n;
		l=n%10;
		n=l;
		if(n==2 or n==4 or n==5 or n==7 or n==9)
			cout<<"hon";
		else if(n==0 or n==6 or n==1 or n==8)
			cout<<"pon";
		else 
			cout<<"bon";
	}
}


Measured memory_bytes: 3576
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


int main(){fastio
    ll cnt=0;
    char t;
    while(cin>>t){
        if(t=='1')cnt++;
    }
    cout<<cnt;
    
    return 0;
}


Measured memory_bytes: 256
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
d = [[1,1],[1,0],[1,-1],[0,1],[0,-1],[-1,-1],[-1,0],[-1,1]]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            cnt = 0
            for x in d:
                if 0 <= i+x[0] < H and 0 <= j+x[1] < W and S[i+x[0]][j+x[1]] == "#":
                    cnt += 1
            S[i][j] = str(cnt)
for i in range(H):
    print("".join(S[i]))

Measured memory_bytes: 3188
n = int(input())
# n, k = list(map(int, input().split()))
# Ch, Cw = list(map(int, input().split()))
# Dh, Dw = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(4)]
# k = int(input())
# a = list(map(int, input().split("/")))
# r = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
# data = [list(map(int, input().split())) for i in range(n)]
# month = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

if n == 0:
    print(1)
else:
    print(0)


Measured memory_bytes: 9072
#include<iostream>
#include<deque>

using namespace std;
using ll = long long;


deque<int> ans1,ans2;

void solve(ll n,int& x){
    if(n==0)return ;
    if(n==1){
        ans1.push_front(x);ans2.push_front(x);
        ++x;
        return;
    }
    solve((n-1)/2,x);
    ans1.push_front(x);ans2.push_front(x);
    ++x;
    if(n%2==0){
        ans1.push_front(x);ans2.push_back(x);
        ++x;
    }
}
int main(){
    ll n;cin>>n;
    int x = 1;
    solve(n,x);
    cout<<ans1.size()+ans2.size()<<endl;
    for(auto e : ans1)cout<<e<<" ";
    for(auto e : ans2)cout<<e<<" ";
    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new FastScanner(System.in)
  val h, w = sc.nextLong()
  val n = sc.nextInt()
  val ab = List.fill(n)((sc.nextInt(), sc.nextInt()))
  var m = Map[(Int, Int), Int]().withDefaultValue(0)
  for ((a, b) <- ab) {
    for {
      i <- -1 to 1
      j <- -1 to 1
      if 1 < a+i && a+i < h && 1 < b+j && b+j < w
    } {
      m += (a+i, b+j) -> (m((a+i, b+j)) + 1)
    }
  }

  val count = m.values.groupBy(identity).view.mapValues(_.size)
  println((w-2) * (h-2) - count.values.sum)
  for (i <- 1 to 9) {
    println(count.getOrElse(i, 0))
  }
}

class FastScanner(source: java.io.InputStream) {
  val buf = new Array[Byte](1024)
  var now, end = 0

  def isPrintable(b: Byte): Boolean = 33 <= b && b <= 126
  def isNum(b: Byte): Boolean = 48 <= b && b <= 57

  def hasNextByte: Boolean = {
    if (now < end) {
      true
    } else {
      now = 0
      end = source.read(buf)
      end > 0
    }
  }

  def nextByte(): Byte = {
    if (hasNextByte) {
      val b = buf(now)
      now += 1
      b
    } else {
      -1
    }
  }

  def hasNext: Boolean = {
    while (hasNextByte && !isPrintable(buf(now))) {
      now += 1
    }
    hasNextByte
  }

  def next(): String = {
    if (hasNext) {
      val sb = new StringBuilder()
      var b = nextByte()
      while (isPrintable(b)) {
        sb += b.toChar
        b = nextByte()
      }
      sb.toString
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextInt(): Int = {
    nextLong().toInt
  }

  def nextLong(): Long = {
    if (hasNext) {
      var b = nextByte()
      var sign = 1
      var n = 0L
      if (b == '-') {
        sign = -1
        b = nextByte()
      }
      while (isNum(b)) {
        n = n * 10 + (b - 48)
        b = nextByte()
      }
      sign * n
    } else {
      throw new NoSuchElementException()
    }
  }

  def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 201616
import java.util.Scanner;


public class Main 
{
	private static int[] prime = new int[99999];
	
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int max = create();
		
		for(; scanner.hasNext(); )
		{
			int n = scanner.nextInt();
			int count = 0;
			for(int i=0; i<max; i++)
			{
				if(n < prime[i])
				{
					break;
				}
				count++;
			}
			
			System.out.println(count);
		}
	}
	
	private static int create()
	{
		int count = 0;
		for(int i=2; i<999999; i+=(i==2)?1:2)
		{
			int p = (int)Math.sqrt(i);
			boolean is_prime = true;
			for(int j=2; j<=p; j+=(j==2)?1:2)
			{
				if(i % j == 0)
				{
					is_prime = false;
					break;
				}
			}
			if(is_prime)
			{
				prime[count++] = i;
			}
		}
		
		return count;
	}
}

Measured memory_bytes: 27088
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int s,w;
  cin >> s >> w;
  if(s<=w){
    cout << "unsafe" <<endl;
  }
  else{
    cout << "safe" <<endl;
  }
  return 0;
}

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

n=int(input())
A=[int(i) for i in input().split()]
if sum(A)%(n*(n+1)//2)!=0:
  print("NO")
else:
  k=sum(A)//(n*(n+1)//2)
  AA=[0]*n
  for i in range(n):
    if i==n-1:
      AA[i]=A[0]-A[-1]-k
    else:
      AA[i]=A[i+1]-A[i]-k
  ans="YES"
  for i in range(n):
    if AA[i]>0 or AA[i]%n!=0:
      ans="NO"
  print(ans)


Measured memory_bytes: 14244
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll n;
    cin>>n;
    ld a[n];
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }

    ld ans=0;
    for(ll i=0;i<n;++i){
        ans+=1/a[i];
    }
    ans=1/ans;
    cout<<setprecision(9)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, w, ans = 0;
int main() {
	cin >> h >> w;
	REPO(i, h) {
		REPO(j, w) {
			ll a;
			cin >> a;
			ans += a * i * (h + 1 - i) * j * (w + 1 - j);
		}
	}
	cout << ans << endl;
}





Measured memory_bytes: 3112
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
    digits = sums = 0
    while num > 0:
        digits += 1
        sums += num % 10
        num //= 10
    return digits, sums


n = int(input())
arr = map(int, input().split())

candidate = [n for n in arr if n % 2 == 0]
for check in candidate:
    if check % 3 != 0 and check % 5 != 0:
        print("DENIED")
        exit()

print("APPROVED")


Measured memory_bytes: 61844
#include<stdio.h>
#include<stdlib.h>
#define INF 5000000
#define WHITE 'W'
#define BLACK 'B'
#define GRAY 'G'
void dijkstra(int,int,int**);
int main()
{
  int n,i,j,k,u,v,**M,l;
  scanf("%d",&n);

  M = malloc(sizeof(int*)*n);
  for(i=0;i<n;i++)
    {
      M[i] = malloc(sizeof(int)*n);
    }

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&u,&k);
      for(l=0;l<n;l++)
        {
          M[u][l]=-1;
        }
      for(j=0;j<k;j++)
        {
          scanf("%d",&v);
          scanf("%d",&M[u][v]);
        }
    }
  dijkstra(0,n,M);
  return 0;
}
void dijkstra(int s,int n,int**M)
{
  int d[100],p[100],i,u,v,mincost;
  char color[100];
  for(u=0;u<n;u++)
    {
      color[u]=WHITE;
      d[u]=INF;
    }
  d[s]=0;
  p[s]=-1;

  while(1)
    {
      mincost=INF;
      for(i=0;i<n;i++)
        {
          if(color[i]!=BLACK && d[i]<mincost)
            {
              mincost = d[i];
              u = i;
            }
        }
      if(mincost==INF) break;

      color[u]=BLACK;

      for(v=0;v<n;v++)
        {
          if(color[v]!=BLACK && M[u][v]>=0)
            {
              if(d[u] + M[u][v] < d[v])
                {
                  d[v] = d[u] + M[u][v];
                  p[v] = u;
                  color[v] = GRAY;
                }
            }
        }
    }
  for(i=0;i<n;i++)
    {
      printf("%d %d\n",i,d[i]);
    }
}


Measured memory_bytes: 2036
#include <cstdio>
#include <vector>

using namespace std;

void precompute(vector <int> &answer_till, int LIMIT)
{
    vector <int> is_prime(LIMIT, true);
    is_prime[0] = is_prime[1] = false;

    vector <int> primes;
    for(int i = 2; i < LIMIT; i++)
    {
        if(is_prime[i])
            primes.push_back(i);

        for(int j = 0; j < primes.size() && i*primes[j] < LIMIT; j++)
        {
            is_prime[i*primes[j]] = false;

            if(i%primes[j] == 0) break;
        }
    }

    for(int i = 3; i < LIMIT; i++)
    {
        answer_till[i] = answer_till[i - 1] + (i%2 == 1 && is_prime[i] && is_prime[(i + 1)/2]);
    }
}

int main()
{
    const int LIMIT = 1e5 + 1;
	vector <int> answer_till(LIMIT, 0);
	precompute(answer_till, LIMIT);

	int no_of_queries;
	scanf("%d", &no_of_queries);

	while(no_of_queries--)
    {
        int left, right;
        scanf("%d %d", &left, &right);
        printf("%d\n", answer_till[right] - answer_till[left - 1]);
    }

	return 0;
}


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

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



void print(vector<int> v){
	
	for(int i=0;i<v.size();i++){
		cout<<v[i];
	}
	//cout<<endl;
}
int N,M,K,A;
int ans=0;

void solve(){
	cin>>N>>M;
	int com[M+1]={0};
	for(int i=0;i<N;i++){
		cin>>K;
		for(int j=0;j<K;j++){
			cin>>A;
			com[A]=com[A]+1;
		}
		
		
	}
	int cnt=0;
	for(int i=0;i<=M;i++){
		//cout<<com[i]<<endl;
	
		if(((com[i]%N)==0)&&(com[i]!=0))cnt++;
		
	}
	cout<<cnt<<endl;
}


int main(){

    solve();
    return 0;
}




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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) &= ~(1 << (b))
#define bitcheck(a, b) ((((a) >> (b)) & 1) == 1)
#define bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

//前処理Ｏ(n)
//クエリ処理Ｏ(log n)
//与えられた区間内の「最小値」を求める。

struct SegmentTree {
  int n;
  vector<int> dat;

  void init(int n_) {
    n = 1;
    while (n < n_) n *= 2;
    dat.resize(2 * n - 1, 0);
  }

  void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = max(dat[2 * k + 1], dat[2 * k + 2]);
    }
  }

  int query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return dat[k];

    int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
    int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
    return max(vl, vr);
  }
};

signed main() {
  int N;
  cin >> N;
  vector<int> h(N), a(N);
  for (int i = 0; i < N; i++) cin >> h[i];
  for (int i = 0; i < N; i++) cin >> a[i];

  SegmentTree dp;
  dp.init(N);

  for (int i = 0; i < N; i++) {
    dp.update(h[i] - 1, a[i] + dp.query(0, h[i]));
  }

  cout << dp.query(0, N) << endl;
  return 0;
}


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

using namespace std;

int main() {
	int N, K;
	int ans = 0;
	vector<int> data[100];
	cin >> N >> K;

	for (int i = 0; i < K; i++) {
		int num;
		cin >> num;
		for (int j = 0; j < num; j++) {
			int tmp;
			cin >> tmp;
			data[tmp-1].push_back(i);
		}
	}
	for (int i = 0; i < N; i++) {
		if (data[i].size() == 0) {
			ans++;
		}
	}
	cout << ans<<endl;
	
}

Measured memory_bytes: 3628
#include <cstdio>
#include <utility>
#include <cctype>
#include <string>
#include <functional>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	string s = in;
	auto i = begin(s);
	function<bool()> is_cat = [&]() {
		return *i == 'm' ? i++, is_cat() && *i++ == 'e' && is_cat() && *i++ == 'w' : true;
	};
	outl(is_cat() && i == end(s) ? "Cat" : "Rabbit");
}


Measured memory_bytes: 2712
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007

int main(){
    long long int n,r=0,g=0,b=0,rgbn=0;
    cin>>n;
    string s;
    cin>>s;
    for(int d=1;d<=n/2;d++){
       
        for(int c=0;c<d;c++){
           for(int i=c;i+2*d<n;i+=d){
            if(s[i]!=s[i+d]&&s[i+d]!=s[i+2*d]&&s[i+2*d]!=s[i])
            rgbn++;
          
           }
        }
    }
    for(int i=0;i<n;i++){
            if(s[i]=='R')
            r++;
            else if(s[i]=='G')
            g++;
            else if(s[i]=='B')
            b++;
        }
        cout<<r*g*b-rgbn<<endl;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.BitSet;
import java.util.Scanner;

//Twenty Questions
public class Main{

	int n, m;
	int[] s;
	BitSet[] yes, no;
	int[][] mem;
	
	int f(int S, int SY){
		if(mem[S][SY]!=-1)return mem[S][SY];
		int res = m;
		BitSet bs = new BitSet(n);
		bs.set(0, n, true);
		for(int j=0;j<m;j++)if(((S>>j)&1)>0){
			if(((SY>>j)&1)>0)bs.and(yes[j]);
			else bs.and(no[j]);
		}
		if(bs.cardinality()<=1)return mem[S][SY] = 0;
		for(int j=0;j<m;j++)if(((S>>j)&1)==0){
			res = Math.min(res, Math.max(f(S|1<<j, SY|1<<j), f(S|1<<j, SY))+1);
		}
		return mem[S][SY] = res;
	}

	void run(){
		Scanner sc = new Scanner(System.in);
		mem = new int[1<<11][1<<11];
		for(;;){
			m = sc.nextInt(); n = sc.nextInt();
			if((m|n)==0)break;
			s = new int[n];
			yes = new BitSet[m];
			no = new BitSet[m];
			for(int i=0;i<m;i++){
				yes[i] = new BitSet(n);
				no[i] = new BitSet(n);
			}
			for(int i=0;i<n;i++){
				s[i] = Integer.parseInt(sc.next(), 2);
				for(int j=0;j<m;j++){
					if(((s[i]>>j)&1)==0)no[j].set(i, true);
					else yes[j].set(i, true);
				}
			}
			for(int[]m:mem)Arrays.fill(m, -1);
			System.out.println(f(0, 0));
		}
	}

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

Measured memory_bytes: 29000
/*input
420 660
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	ll a, b; cin >> a >> b;
	ll g = __gcd(a, b);
	int ans = 1;
	if (g % 2 == 0) {
		++ans;
		while (g % 2 == 0)
			g /= 2;
	}
	for (ll i = 3; i * i <= g; i += 2) {
		if (g % i == 0) {
			++ans;
			while (g % i == 0) {
				g /= i;
			}
		}
	}
	if (g > 2) ++ans;
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int m;
int board[92][92];
int tmp[92][92];
int ans;
bool flag[91][91];
int dfs(int y,int x,int cnt){
	int a = cnt;
	for(int i = 0;i < 4;i++){
		int nx = x +dx[i];
		int ny = y + dy[i];
		if(nx<0||nx >=m||ny <0||ny >=n||board[ny][nx]==0)
			continue;
		board[ny][nx] = 0;
		a = max(a,dfs(ny,nx,cnt+1));
		board[ny][nx] = 1;
	}
	return a;
}

int main(){
	while(cin>>n>>m,n||m){
		ans = 0;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				cin>>board[i][j];
			}
		}
		for(int i = 0;i < n;i++){
			for(int j = 0;j < m;j++){
				if(board[i][j]==1){
					board[i][j] = 0;
					ans =max(ans,dfs(i,j,1));
					board[i][j] = 1;
				}
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    int a[h][w], b[h][w];
    int diff[h][w];
    for(int x = 0; x < h; x ++){
        for(int y = 0; y < w; y ++){
            cin >> a[x][y];
        }
    }
    for(int x = 0; x < h; x ++){
        for(int y = 0; y < w; y ++){
            cin >> b[x][y];
        }
    }
    for(int x = 0; x < h; x ++){
        for(int y = 0; y < w; y ++){
            diff[x][y] = abs(a[x][y]-b[x][y]);
        }
    }
    int x = 0, y = 0;
    int base = 80*80;
    int lim = base*2;
    vector<vector<vector<int>>> dp(h, vector<vector<int>>(w, vector<int>(lim+1, 0)));
    dp[0][0][diff[0][0]] = 1;
    for(int x = 0; x < h; x ++){
        for(int y = 0; y < w; y ++){
            for(int d = 0; d <= lim; d ++){
                if(x != 0){
                    dp[x][y][d] = max(dp[x][y][d], dp[x-1][y][abs(d-diff[x][y])]);
                    if(d + diff[x][y] <= lim){
                        dp[x][y][d] = max(dp[x][y][d], dp[x-1][y][d+diff[x][y]]);
                    }
                }
                if(y != 0){
                    dp[x][y][d] = max(dp[x][y][d], dp[x][y-1][abs(d-diff[x][y])]);
                    if(d + diff[x][y] <= lim){
                        dp[x][y][d] = max(dp[x][y][d], dp[x][y-1][d+diff[x][y]]);
                    }
                }
            }
        }
    }
    for(int d = 0; d <= base; d++){
        if(dp[h-1][w-1][d] == 1){
            cout << d << endl;
            return 0;
        }
    }
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;cin>>s;
    int n=s.size();
    ll dpa[n+1],dpab[n+1],dpabc[n+1];
    vl a(n+1);
    a[0]=1;
    for(int i=0;i<n;++i){
        a[i+1]=3*a[i];
        a[i+1]%=MOD;
    }
    mem(dpa,0);mem(dpab,0);mem(dpabc,0);
    int cnt=0;
    if(s[0]=='A'||s[0]=='?'){
        dpa[0]=1;
    }
    if(s[0]=='?')cnt++;
    for(int i=0;i<n-1;++i){
        if(s[i+1]=='?'){
            dpa[i+1]=dpa[i]*3+a[cnt];
            dpa[i+1]%=MOD;
            dpab[i+1]=dpab[i]*3+dpa[i];
            dpab[i+1]%=MOD;
            dpabc[i+1]=dpabc[i]*3+dpab[i];
            dpabc[i+1]%=MOD;
            cnt++;
        }
        else if(s[i+1]=='A'){
            dpa[i+1]=dpa[i]+a[cnt];
            dpa[i+1]%=MOD;
            dpab[i+1]=dpab[i];
            dpabc[i+1]=dpabc[i];
        }
        else if(s[i+1]=='B'){
            dpa[i+1]=dpa[i];
            dpab[i+1]=dpab[i]+dpa[i];
            dpab[i+1]%=MOD;
            dpabc[i+1]=dpabc[i];
        }
        else if(s[i+1]=='C'){
            dpa[i+1]=dpa[i];
            dpab[i+1]=dpab[i];
            dpabc[i+1]=dpabc[i]+dpab[i];
            dpabc[i+1]%=MOD;
        }
    }
    cout<<dpabc[n-1]<<endl;
}

Measured memory_bytes: 6708
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>


int main() {
	std::string str; std::cin >> str;
	auto is_good = true;
	for (auto i = 1; i < str.size(); ++i) {
		if (str[i] == str[i - 1]) {
			is_good = false;
			break;
		}
	}
	if (is_good) {
		std::cout << "Good\n";
	}
	else {
		std::cout << "Bad\n";
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
using ll = long long int;
#define REP(i,n) for(int i=0;i<n;i++)

int main()
{
    ll N;
    cin >> N;
    
    ll power = 1;
    for(ll i = 1; i <= N; i++)
    {
        power = (power * i) % (long)(1e9 + 7);
    }

    cout << power << endl;
    
}

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}


int main()
{
    ll N,M,ans=-100;
    cin >> N >> M;

    if(M==0){
        if(N==1){
            ans =0;
            cout << ans <<endl;
            return 0;
        }else if(N==2){
            ans =10;
            cout << ans <<endl;
            return 0;
        }else{
            ans =100;
            cout << ans <<endl;
            return 0;
        }
    }

    ll dig[N];
    rep(i,N) dig[i]=-100;


    ll s,c;
    rep(i,M) {
        cin >> s >> c;
        s = s-1;
        if(dig[s]!=-100 && dig[s] !=c){
            ans=-1;
            cout << ans <<endl;
            return 0;
        }else{
            dig[s]= c;
        }
    }

    rep(i,N){
        if(i==0){
            if(dig[i]==-100){
                dig[i]=1;
            }
        }else{
            if(dig[i]==-100){
                dig[i]=0;
            }            
        }
    }

    if(ans!=-1){
        ans=0;
        rep(i,N){
            ans += dig[i]*pow_kai(10,N-1-i);
        }
    }

    if(dig[0]==0){
        ans=-1;
    }

    if(dig[0]==0 && N==1){
        ans=0;
    }



    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
	Scanner scanner = new Scanner(System.in);

	String s = scanner.next();

	scanner.close();

	int stringLength = s.length();

	// 1
	String sReverse = reverseString(s);
	boolean firstCondition = s.equals(sReverse);

	// 2
	int partLength = (stringLength - 1) / 2;

	String sPart = s.substring(0, partLength);
	String sPartReverse = reverseString(sPart);
	boolean secondCondition = sPart.equals(sPartReverse);

	// 3
	int otherPartLength = (stringLength + 3) / 2 - 1;

	String sOtherPart = s.substring(otherPartLength, stringLength);
	boolean thirdCondition = sOtherPart.equals(reverseString(sOtherPart));

	String result;

	if (firstCondition && secondCondition && thirdCondition)
	{
	    result = "Yes";
	}
	else
	{
	    result = "No";
	}

	System.out.println(result);
    }

    private static String reverseString(String s)
    {
	return new StringBuilder(s).reverse().toString();
    }

}

Measured memory_bytes: 23764
//AnkitCode99 here....
//every ups and downs matter!

#include<bits/stdc++.h>
#define endl "\n"
#define Ryuga ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr)
typedef long long int ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back

using namespace std;

const ll sz=1e5+5;
const ll szz=1e6+6;
const ll mod=1e9+7;

int main()
{
	Ryuga;

	
	clock_t startTime=clock();

	ll a;
	cin>>a;
	cout<< a+a*a+a*a*a;

	cerr << endl <<setprecision(20)<< double( clock() - startTime ) / (double)CLOCKS_PER_SEC<< " seconds." << endl;

}//Goodbye...

Measured memory_bytes: 3764
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int h,w;
	scanf("%d %d",&h,&w);
	int n,a[10010];
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int k=1,s[110][110];
	for(int i=1;i<=h;i++)
	{
		if(i%2!=0)
		{
			for(int j=1;j<=w;j++)
			{
				if(a[k]!=0)
				{
					s[i][j]=k;
					a[k]--;
				}
				else
				{
					while(a[k]==0)
					{
						k++;
					}
					s[i][j]=k;
					a[k]--;
				}
			}
		}
		else
		{
			for(int j=w;j>=1;j--)
			{
				if(a[k]!=0)
				{
					s[i][j]=k;
					a[k]--;
				}
				else
				{
					while(a[k]==0)
					{
						k++;
					}
					s[i][j]=k;
					a[k]--;
				}
			}
		}
	}
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(j!=1)
			{
				printf(" ");
			}
			printf("%d",s[i][j]);
		}
		printf("\n");
	}
} 

Measured memory_bytes: 384
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    int N, cnt(0); std::cin >> N;
    {
        int a;
        for(int i(0); i < N; ++i){
            std::cin >> a;
            if(!(i % 2) && (a % 2)) ++cnt;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll n, l;
  cin >> n >> l;
  vector<string> s(n);
  for (ll i = 0; i < n; i++) cin >> s[i];
  sort(all(s));
  for (ll i = 0; i < n; i++) cout << s[i];
  cout << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def main():
    N,S,Q,*q = read().decode().split()
    N = int(N)
    S = list(S)

    c = lambda x: ord(x) - ord('a')
    tree = [SegmentTree(N, lambda x,y:x|y) for _ in range(26)]
    for i, l in enumerate(S):
        tree[c(l)].update(i, 1)

    for t, a, b in zip(*[iter(q)]*3):
        if t == '1':
            a = int(a) - 1
            tree[c(S[a])].update(a, 0)
            tree[c(b)].update(a, 1)
            S[a] = b
        else:
            a, b = int(a)-1, int(b)-1
            ans = 0
            for i in range(26):
                t = tree[i].query(a, b+1)
                ans += 1 if t else 0
            print(ans)

class SegmentTree:
    def __init__(self, n=None, f=max, zero_factory=int, converter=lambda x:x, initial_values=None):
        assert(n or initial_values)
        size = n if n else len(initial_values)
        self.__f, self.__z, self.__c = f, zero_factory, converter
        self.__n = 1 << ((size - 1).bit_length())
        self.__dat = [zero_factory() for _ in range(2 * self.__n)]
        if initial_values:
            zi = self.__get_leaf(0)
            for i, v in enumerate(initial_values): self.__dat[zi + i] = converter(v)
            for i in range(zi-1, -1, -1): self.__dat[i] = f(*self.__get_children(i))

    def update(self, index, value):
        i, v = self.__get_leaf(index), self.__c(value)
        if self.__dat[i] == v: return
        self.__dat[i] = v
        while i:
            i = self.__get_parent(i)
            self.__dat[i] = self.__f(*self.__get_children(i))

    def query(self, from_inclusive, to_exclusive):
        ans = self.__z()
        if to_exclusive <= from_inclusive: return ans
        l, r = self.__get_leaf(from_inclusive), self.__get_leaf(to_exclusive) - 1
        while r - l > 1:
            if self.__is_right(l): ans = self.__f(ans, self.__dat[l])
            if self.__is_left(r): ans, r = self.__f(ans, self.__dat[r]), r-1
            l, r = l//2, self.__get_parent(r)
        ans = self.__f(ans, self.__dat[l])
        if l != r: ans = self.__f(ans, self.__dat[r])
        return ans

    def __get_leaf(self, i): return self.__n + i - 1
    def __get_parent(self, i): return (i-1)//2
    def __get_children(self, i): return (self.__dat[2*i+1], self.__dat[2*i+2])
    def __is_left(self, i): return i&1 == 1
    def __is_right(self, i): return i&1 == 0

if __name__ == '__main__':
    main()


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

int main(){
    string s;
    cin>>s;
    reverse(all(s));
    bool flag=0;
    ll i=0;
    while(i<s.size()){
        if(s.substr(i,5)=="maerd") i+=5;
        else if(s.substr(i,7)=="remaerd") i+=7;
        else if(s.substr(i,5)=="esare") i+=5;
        else if(s.substr(i,6)=="resare") i+=6;
        else break;
        if(i==s.size()) flag=1;
    }
    cout<<(flag?"YES":"NO")<<endl;
    return 0;
}

Measured memory_bytes: 512