akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int[] a = new int[3];
        int max = 0;
        int total = 0;
        for(int i = 0; i < 3; i++){
            a[i] = sc.nextInt();
            max = Math.max(max,a[i]);
            total += a[i];
        }
        System.out.println((max*3-total) % 2 == 0 ? (max*3-total)/2 : (max*3-total)/2+2);
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

const int INF = 1e9+7;

vector<int> bfs(int s, vector<vector<int>> &graph) {
  vector<bool> visited((int)graph.size(), false);
  vector<int> dist((int)graph.size(), INF);
  dist[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int u = q.front(); q.pop();
    if (visited[u]) continue;
    visited[u] = true;
    for (int v: graph[u]) {
      if (visited[v]) continue;
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }

  return dist;
};

// vector<int> dfs(int s, vector<vector<int>> &graph, vector<int> &dist_from_init_A) {
//   vector<bool> visited((int)graph.size(), false);
//   vector<int> dist((int)graph.size(), INF);
//   dist[s] = 0;
//   queue<int> q;
//   q.push(s);
//   while (!q.empty()) {
//     int u = q.front(); q.pop();
//     if (visited[u]) continue;
//     visited[u] = true;
//     for (int v: graph[u]) {
//       if (visited[v]) continue;
//       if (dist[v] > dist[u] + 1) {

//       }
//     }
//   }
// };

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

  int N, u, v;
  cin >> N >> u >> v;
  u--; v--;
  vector<vector<int>> graph(N);
  int a, b;
  rep(i, 0, N-1) {
    cin >> a >> b;
    a--; b--;
    graph[a].pb(b);
    graph[b].pb(a);
  }

  vector<int> dist_from_init_A = bfs(v, graph);
  vector<int> dist_from_init_T = bfs(u, graph);

  int ans = 0;
  rep(i, 0, N) {
    int d_from_t = dist_from_init_T[i];
    int d_from_a = dist_from_init_A[i];
    if (d_from_t <= d_from_a) {
      ans = max(ans, d_from_a - 1);
    }
  }

  cout << ans << endl;

  return 0;
};


Measured memory_bytes: 6656
s=str(input())
abc=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = "None"
sort_s = sorted(s)
# print(sort_s)
for i in abc:
    if (i in sort_s) == False:
        ans = i
        break
print(ans)

Measured memory_bytes: 4280
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>

#define div1 1000000007

using namespace std;

int main(void)
{
    long long H, N, A[100001], i, sum=0;

    cin >> H >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];

        sum += A[i];
    }

    if(sum >= H){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define me(a,b) memset(a,b,sizeof(a))
#define INIT() std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
const int MAX_N=200000+5;
const int MAX_M=100000+5;
const int INF=0x7fffffff;
const int inf=1000000000;
const double EPS=1e-6;
const ull base=123;
const ll mod=1e9+7;
const double pi=4*atan(1.0);
int a[MAX_N];
int main()
{
    int n;
    cin>>n;
    int i;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int j,k;
    int ans=0;
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            for(k=j+1;k<=n;k++)
            {
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]){
                    //cout<<i<<' '<<j<<' '<<k<<endl;
                    ans++;}
            }
        }
    }
    cout<<ans<<endl;
    //system("pause");
    
}

Measured memory_bytes: 3680
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <math.h>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t target[200000];
int32_t attack[200000];
std::vector<int64_t> V;//cost,value
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	bool diff = false;
	for (int32_t i = 0; i < N; i++)
	{
		in >> target[i] >> attack[i];
		diff |= (target[i] != attack[i]);
	}
	if (diff == false) {
		out << 0 << endl;
		return 0;
	}

	int64_t count = 0;
	for (int32_t i = 0; i < N; i++)
	{
		if (target[i] <= attack[i]) {
			count += attack[i];
		}
		else {
			count += attack[i];
			V.emplace_back(attack[i]);
		}
	}
	std::sort(V.begin(), V.end());


	out << count-V[0] << endl;


	return 0;
}
#endif


Measured memory_bytes: 640
import java.io.*;
import java.util.*;

public class Main {

	void submit() {
		int h = nextInt();
		int w = nextInt();
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		
		int[][] ret = new int[h][w];
		int ptr = 0;
		
		for (int i = 0; i < h; i++) {
			int y, step;
			if (i % 2 == 0) {
				y = 0;
				step = 1;
			} else {
				y = w - 1;
				step = -1;
			}
			
			for (int j = 0; j < w; j++, y += step) {
				ret[i][y] = ptr + 1;
				a[ptr]--;
				if (a[ptr] == 0) {
					ptr++;
				}
			}
		}
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				out.print(ret[i][j] + " ");
			}
			out.println();
		}
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		//stress();
		//test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 23764
// Last Change: 08/18/2019 21:57:16.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
  ll N, Q;
  cin >> N >> Q;

  vector<ll> node(N, 0);
  vector<list<ll>> edge(N, list<ll>());
  ll a, b, p, x;
  for (ll i = 0; i < N - 1; ++i) {
    cin >> a >> b;
    --a, --b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for (ll i = 0; i < Q; ++i) {
    cin >> p >> x;
    --p;
    node[p] += x;
  }

  vector<int> reached(N, 0);
  // place, val
  stack<pair<ll, ll>> cur;
  cur.push(make_pair(0, 0));
  while (!cur.empty()) {
    pair<ll, ll> next = cur.top();
    cur.pop();
    node[next.first] += next.second;
    reached[next.first] = 1;
    for (auto &&e : edge[next.first]) {
      if (reached[e] > 0) {
        continue;
      }
      cur.push(make_pair(e, node[next.first]));
    }
  }

  for (auto &&e : node) {
    cout << e << ' ';
  }
  cout << endl;
}



Measured memory_bytes: 22128
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int n, x = 0, y = 0, t = 0;
	cin >> n;
	bool flag = true;
	for(int i = 0; i < n; i++){
		int ti, xi, yi;
		cin >> ti >> xi >> yi;
		int dt = ti - t;
		int dx = abs(xi - x);
		int dy = abs(yi - y);
		if (dx + dy > dt){
			flag = false;
		}
		else if (dx > dy){
			int r = dt - dx;
			if((r - dy) % 2 == 1)
				flag = false;
		}
		else{
			int r = dt - dy;
			if((r - dx) % 2 == 1)
				flag = false;
		}
		t = ti;
		x = xi;
		y = yi;
	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
import copy
import queue
q = queue.Queue()
n = int(input())

neib = []
level = []
for i in range(n):
    neib.append([])
    level.append([i,-1])
for i in range(n-1):
    a,b = map(int,input().split())
    neib[a-1].append(b-1)
    neib[b-1].append(a-1)

def bfs():
    start = 0
    valid = [1]*100001
    q.put((start,0)) 
    valid[start] = 0
    level[start][1] = 0
    while not q.empty():
        p,d = q.get()
        for nei in neib[p]:
            if valid[nei]:
                valid[nei]=0
                level[nei][1] = d+1
                q.put((nei,d+1))
bfs()

level.sort(key = lambda x:x[1])
c = list(map(int,input().split()))
c.sort(reverse=True)
res = 0
for i in range(n):
    level[i].append(c[i])
    res += c[i]
res -= c[0]
print(res)
level.sort(key = lambda x:x[0])
for i in range(n):
    print(level[i][2],end=" ")
print("")


Measured memory_bytes: 8800
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n, m;
int vis[N], dist[N], ways[N], ans[N];
vector<int> g[N];

void bfs(int k)
{
	queue<int> q;
	q.push(k);
	vis[k] = 1;
	while(!q.empty())
	{
		int node=q.front();
		q.pop();
		for(auto it:g[node])
		{
			if(!vis[it])
			{
				dist[it] = dist[node] + 1;
				vis[it] = 1;
				ans[it] = node;
				q.push(it);
			}
		}
	}
	for(int i = 1; i <= n; i++)
	{
		if(!vis[i])
		{
			cout << "No";
			exit(0);
		}
	}
}


int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	bfs(1);
	cout << "Yes" << endl;
	for(int i = 2; i <= n; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 16988
A, B = map(int, input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

ap = prime_factorize(A)
bp = prime_factorize(B)

print(len(set(ap) & set(bp)) + 1)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        S = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "");
        
        if (S.length() == 0) {
            System.out.println("YES");
        } else {
            System.out.println("NO");    
        }
    }
}

Measured memory_bytes: 28580
#include "bits/stdc++.h"


// vector
#define MAX_ELE(vec) *max_element(vec.begin(), vec.end())
#define SORT(vec) sort(vec.begin(), vec.end());


// ---------------------------------------

// string
#define TO_UP(str) transform(str.cbegin(), str.cend(), str.begin(), ::toupper)

// ---------------------------------------



using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
//  --------------------------------------

    unordered_map<string, int> pat;
    int N;
    long long ans = 0;

    string sss;
    
    cin >> N;

    for (int i = 0; i < N; i++)
    {
        cin >> sss;
        SORT(sss);
        if(pat.count(sss))
        {
            ans += pat[sss];
            pat[sss] += 1;
        }
        else
        {
            pat[sss] = 1;
        }

    }

    cout << ans << "\n";
    

}

Measured memory_bytes: 10660
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>

using ll = long long;

#define onWall(x, y) (x % r == 0 || y % c == 0)

using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

int main() {
    int r, c, n;
    cin >> r >> c >> n;
    vector<int> wall;
    P points[200000];
    for (int i=0, x1, x2, y1, y2; i<n; i++) {
        cin >> x1 >> y1 >> x2 >> y2;
        points[i] = {x1, y1};
        points[i+n] = {x2, y2};
        if (onWall(x1, y1) && onWall(x2, y2)) {
            wall.push_back(i);
            wall.push_back(i+n);
        }
    }
    auto to_line = [&](P p){
        int x = p.fi, y = p.se;
        if (y==0) return x;
        if (x==r) return r+y;
        if (y==c) return r+c+r-x;
        return r+c+r+c-y;
    };
    sort(wall.begin(), wall.end(), [&](int a, int b) {
        P ap = points[a], bp = points[b];
        return to_line(ap) < to_line(bp);
    });
    stack<int> st;
    for (auto w:wall) {
        w %= n;
        if (!st.empty() && w == st.top()) st.pop();
        else st.push(w);
    }
    cout << (st.empty() ? "YES" : "NO") << '\n';
    return 0;
}

Measured memory_bytes: 2936
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
const int INF = 1e9;
int gcd(int a, int b){ //a>=0,b>=0,￢(a=b=0)
  while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);
}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
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 dp[100005];
int h[100005];
signed main(){
  int n;
  cin>>n;
  rep(i,n)cin>>h[i];
  rep(i,n) dp[i]=INF;
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  FOR(i,2,n-1){
    chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));

    // dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


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

int main()
{
	int w, a, b;
	
	scanf("%d%d%d", &w, &a, &b);
	if (a <= b && b <= a + w || a <= b + w && b + w <= a + w) {
		puts("0");
	} else {
		printf("%d\n", min(abs(a - b), min(abs(a - b - w), min(abs(a + w - b), abs(a + w - b - w)))));
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod

// #define LOCAL 1

/************************************


 
*************************************/

vector<int>par,dep,tin,tout;
vector<vector<int>>v;
vector<int>deg;
vector<pll>req;
bool visited[MAX];






void solve(){
    int t=1;
    // cin>>t;
    while(t--){
        int n,m;
        cin>>n;
        double ans = 2*3.1415926535897*n;
        cout<<ans<<"\n";
        

        
    }
}


signed main() 
{ 
    boost;

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s;
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
    #else
        solve();
    #endif




    

    
	return 0; 
} 

Measured memory_bytes: 3808
def main():
    n = int(input())
    h = list(map(int, input().split()))
    m = []
    i = 0
    while i < n:
        mc = move(i, h)
        #print(i, mc)
        m.append(mc)
        i += max(mc, 1)
    return max(m)

def move(i, arr):
    c = 0
    while i + 1 < len(arr) and arr[i] >= arr[i+1]:
        c += 1
        i += 1
    return c

if __name__ == "__main__":
    print(main())

Measured memory_bytes: 14224
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <utility>
#include <queue>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
using namespace std;
#define sL(i) i << 1
#define sR(i) i << 1 | 1
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<int, pair<int,int>> ppi;
const int MOD = 1e9 + 7;
const int INF = 2e9 + 5;
const int MAXN  = 300010;

int h, w, m;
int x[MAXN], y[MAXN];

int rows[MAXN], cols[MAXN];
int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w >> m;
    set<pi> locations;
    for (int i = 0; i < m; i++) {
        cin >> x[i] >> y[i];
        locations.emplace(x[i], y[i]);
        ++rows[x[i]];
        ++cols[y[i]];
    }
    int rowVal = *max_element(rows, rows+h+1);
    int colVal = *max_element(cols, cols+w+1);
    vector<int> maxrows, maxcols;
    for (int i = 1; i <= h; i++) {
        if (rows[i] == rowVal) maxrows.push_back(i);
    }
    for (int i = 1; i <= w; i++) {
        if (cols[i] == colVal) maxcols.push_back(i);
    }
    int ans = 0;
    if ((ll) maxrows.size() * maxcols.size() <= m) {
        bool found = false;
        for (int i : maxrows) {
            for (int j : maxcols) {
                if (!locations.count({i, j})) {
                    found = true;
                }
            }
        }
        if (found) ans = rowVal + colVal;
        else ans = rowVal + colVal - 1;
    } else {
        ans = rowVal + colVal;
    }
    cout << ans;
}

Measured memory_bytes: 25816
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
    }

    for i in 0..m {
        let mut l = 1 + 2 * i;
        if n % 2 == 0 && l >= n / 2 {
            l += 1;
        }
        let j = i + n - l;
        println!("{} {}", i + 1, (j % n + 1));
    }
}


Measured memory_bytes: 2204
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		int n = Integer.parseInt(sc.next());
	
		int []a = new int [n];
		int []b = new int [n];
	
		data []d = new data[n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
			b[i] = Integer.parseInt(sc.next());
		}
		
		for(int i = 0 ;i < n ;i++) {
			d[i] = new data(a[i] , b[i]);
		}
		
		Arrays.sort(d, new Comparator<data>(){
			public int compare(data d1 ,data d2) {
				int temp = d1.getA() - d1.getA();
				if(temp == 0) {
					return d1.getB() -d2.getB();
				}
				return temp;
			}
		});
		
		long sum = 0;
		boolean flag = true;
		
		for(int i = 0 ; i < n ;i++) {
			sum += d[i].getA();
			if(sum > d[i].getB()) {
				flag = false;
				break;
			}
		}
		
		if(flag) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
	
	
	
	}   
}
class data{
	private int a;
	private int b;
	
	 public data(int a ,int b){
		this.a = a;
		this.b = b;	
	}
	 public int getA() {
		 return a;
	 }
	 public int getB() {
		 return b;
	 }
}




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

int main(){
string S;
  cin>>S;
  
  vector<bool>flag(100000, false);
  flag[0]=true;
  for(int i=0; i<S.size(); i++){
   if(flag[i]==false){continue;}
   if(i+5<=S.size() && S.substr(i, 5)=="dream"){flag[i+5]=true;} //次の単語の先頭をtrueにする
   if(i+5<=S.size() && S.substr(i, 5)=="erase"){flag[i+5]=true;}
   if(i+6<=S.size() && S.substr(i, 6)=="eraser"){flag[i+6]=true;}
   if(i+7<=S.size() && S.substr(i, 7)=="dreamer"){flag[i+7]=true;}
  }
  
  if(flag[S.size()]){cout<<"YES";} // Sが上記の単語で構成されていた場合は、
  else{cout<<"NO";}  // flag[S.size()]==trueになる。
}  // そうでない場合は上記以外の単語以降はfalseになる。 

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    ll tmin = 0;
    ll tmax = 0;
    for(int i = 1; i <= n+1; i++){
        tmin += (i-1);
        tmax += n - (i-1);
        if(i < k){continue;}
        ans += tmax - tmin + 1;
        ans %= MOD;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3644
import sys

in_str=input()
in_str1=list(in_str)

flag1=-1
flag2=-1

if in_str[0]=='A':
    flag1=0
    
if in_str[2:-1].count("C")==1:
    flag2=2+in_str[2:-1].index("C")
    
if flag1!=-1 and flag2!=-1:
    in_str1[flag1]="a"
    in_str1[flag2]="c"
    in_str2=list(in_str.lower())
    if in_str1==in_str2:
        print("AC")
        sys.exit()
print("WA")
    

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ll long long
#define inf 1e9
#define eps 1e-10
#define mod 9901
#define mkp make_pair
using namespace std;
int i,j,k,m,s,t,n,ans1,ans2,n1,nn,m1,mx;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int kabs(int a)
{
   if (a<0) return -a;
   return a; 
}
void add(int &x,int y)
{
   x+=y;
   if (x>=mod) x-=mod;
}
void dec(int &x,int y)
{
	x-=y;
	if (x<0) x+=mod;
}
int a[101000];
ll f[101000];
int main()
{
	int e;
	scanf("%d%d%d",&n,&e,&t);
	for (i=1;i<=n;i++)
		scanf("%d",&a[i]);
	j=0;
	ll s=1e18;
	for (i=1;i<=n;i++)
		f[i]=1e18;
	for (i=1;i<=n;i++)
	{
		while (2*(a[i]-a[j+1])>=t)
			s=min(s,f[j]-2ll*a[j+1]),j++;
		f[i]=min(f[j]+t,2ll*a[i]+s);
	}
	printf("%lld\n",f[n]+e);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  long long ans=1000000000;
  long long sum=0;
  for(int j=1;j<101;j++){
    for(int i=0;i<n;i++){
      sum+=(a[i]-j)*(a[i]-j);
    }
    ans=min(ans,sum);
    sum=0;
  }
  cout<<ans<<endl;
}

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

int main(){
        int h, w;
        char a[8][8];

        cin>>h>>w;
        int cnt=0;
        for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                        cin>>a[i][j];
                        if(a[i][j]=='#') cnt++;
                }
        }

        int x=0,y=0;
        bool ans;
        cnt--;
        while(1){
                if(x==w-1 && y==h-1){
                        if(cnt==0) ans=true;
                        else ans=false;
                        break;
                }
                if(x+1<w && a[y][x+1]=='#') x++;
                else if(y+1<h && a[y+1][x]=='#') y++;
                else{
                        ans=false;
                        break;
                }
                cnt--;
        }

        if(ans) cout<<"Possible"<<endl;
        else cout<<"Impossible"<<endl;

        return 0;
}


Measured memory_bytes: 384
local n=io.read("n")

local pable={}
for i=1,n do
    local x=i
    for j=2,math.sqrt(x) do
        if x%j==0 then
            local counter=0
            while x%j==0 do
                x=x//j
                counter=counter+1
            end
            pable[j]=(pable[j] or 0)+counter
        end
    end
    if x>1 then
        pable[x]=(pable[x] or 0)+1
    end
end

local div=1
for k,v in pairs(pable) do
    div=div*(v+1)%1000000007
end
print(div)

Measured memory_bytes: 760
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int n, a, b, c;
vector<int> l;

int dfs(int cur, int a_, int b_, int c_) {
	if (cur == n) {
		if (!a_ || !b_ || !c_) return INF;	//一本は使う
		return abs(a - a_) + abs(b - b_) + abs(c - c_);
	}
	int r0 = dfs(cur + 1, a_         , b_         , c_         );
	int r1 = dfs(cur + 1, a_ + l[cur], b_         , c_         ) + (a_ ? 10 : 0);
	int r2 = dfs(cur + 1, a_         , b_ + l[cur], c_         ) + (b_ ? 10 : 0);
	int r3 = dfs(cur + 1, a_         , b_         , c_ + l[cur]) + (c_ ? 10 : 0);
	return min(r0, min(r1, min(r2, r3)));
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	cin >> n >> a >> b >> c;
	l.resize(n);
	rep(i, n) cin >> l[i];

	out(dfs(0, 0, 0, 0));

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())

switches = []
for i in range(m):
    tmp_list = list(map(int, input().split()))
    switches.append(tmp_list[1:])
values = list(map(int, input().split()))

on_offs = [i for i in range(2 ** n)]

count = 0
for i in range(2 ** n):
    ng = False
    for p, s_list in zip(values, switches):
        # print(f'i = {i}')
        on_count = 0
        # print(s_list)
        for s in s_list:
            if (i >> (s - 1)) & 1:
                # print(i, s - 1)
                on_count += 1
        # print(i, on_count)
        if on_count % 2 != p:
            ng = True
            break
    if not ng:
        # print(i)
        count += 1

print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>

using namespace std;

int n,m;

int main(void){
	scanf("%d",&n);
	scanf("%d",&m);
	int maxi=m;
	for(int i=0;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		m+=a;
		m-=b;
		if(m<0){
			printf("0\n");
			return 0;
		}
		maxi=max(m,maxi);
	}
	printf("%d\n",maxi);
	return 0;
}

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

a_list = list(map(int, input().split()))

b_list = []
for i, a in enumerate(a_list):
    b_list.append((i+1, a))

b_list = sorted(b_list, key=lambda x: int(x[1]))

c_list = []
for i, b in b_list:
    c_list.append(str(i))

print(' '.join(c_list))

Measured memory_bytes: 25312
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		//Scanner s = new Scanner(System.in);
		Scanner s = new Scanner(System.in);
		int N = s.nextInt();
		int[] S = new int[N];
		boolean flg = false;
		for(int i = 0;i < N;i++){
			flg |= s.next().equals("Y");
		}
		
		System.out.println(flg ? "Four" : "Three");
		
		
	}

}


Measured memory_bytes: 22868
import random
class Dice:
    def __init__(self,surfaceNum):
        self.surface = surfaceNum
        
    def east(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[3], self.surface[0], self.surface[2], self.surface[5]
    def west(self):
        self.surface[0], self.surface[2], self.surface[5], self.surface[3] = self.surface[2], self.surface[5], self.surface[3], self.surface[0]
    def south(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[4], self.surface[0], self.surface[1], self.surface[5]
    def north(self):
        self.surface[0], self.surface[1], self.surface[5], self.surface[4] = self.surface[1], self.surface[5], self.surface[4], self.surface[0]
        
    def printTopSurface(self):
        print(self.surface[0])  
    def printRight(self):
        print(self.surface[2])

surfaceNum = [int(i) for i in input().split()]
commandNum = int(input())
rollCommandList = ["E", "W", "S", "N"]
Dice = Dice(surfaceNum)
rightNum = [0]*commandNum

for i in range(commandNum):
    topFront = [int(data) for data in input().split()]
    while Dice.surface[0] != topFront[0] or Dice.surface[1] != topFront[1]:
        rollCommand = random.choice(rollCommandList)
        if rollCommand == "E":
            Dice.east()
        if rollCommand == "W":
            Dice.west()
        if rollCommand == "S":
            Dice.south()
        if rollCommand == "N":
            Dice.north()
    rightNum[i] = Dice.surface[2]
for i in range(commandNum):
    print(rightNum[i])




Measured memory_bytes: 8196
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <map>
#include <queue>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;

typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;

//るんるん数

//1,2,3,4,...9
//10,11,12
//13はるんるん数ではない


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

    queue <ll> q;

    for(int i = 1; i <= 9; ++i)
    {
        q.push(i);
    }

    for(int i = 0; i < K-1; ++i)
    {
        ll x = q.front();
        q.pop();
        ll y;

        if(x % 10 != 0)
        {
            y = 10 * x + x % 10 - 1;
            q.push(y);
        }
        
        y = 10 * x + x % 10;
        q.push(y);

        if(x % 10 != 9)
        {
            y = 10 * x + x % 10 + 1;
            q.push(y);
        }
    }
    ll res = q.front();
    cout << res << endl;



    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	char s;
	cin >> s;
	if (s == 'A')
		cout << 'T' << endl;
	if (s == 'T')
		cout << 'A' << endl;
	if (s == 'G')
		cout << 'C' << endl;
	if (s == 'C')
		cout << 'G' << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Text;

public class Program{
    public static void Main(){
        var watch = new Stopwatch();
        watch.Start();
        var isTest = false;
        var stream = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
        Console.SetOut(stream);
        TextReader reader;
        string filename="";
        
        if(filename.Length!=0){
            reader = new StreamReader(filename);
        }else{
            reader = Console.In;
        }

        var rgb = reader.ReadLine().Split().Select(int.Parse).ToArray();
        var ans = (rgb[0]*100+rgb[1]*10+rgb[2])%4 == 0 ? "YES" : "NO";
        Console.WriteLine(ans);



        watch.Stop();
        if(isTest){
            Console.WriteLine($"実行時間{watch.ElapsedMilliseconds}ミリ秒");
        }
        Console.Out.Flush();
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  int N;
  cin >> N;
  
  map<string, int> memo;
  string s;
  
  rep(i, N){
    cin >> s;
    memo[s]++;
  }
  
  int max_number = 0;
  for (const auto& x : memo){
    if (max_number < x.second){
      max_number = x.second;
    }
  }
  
  for (auto&& itr = memo.begin(); itr != memo.end(); itr++){
    if(itr->second == max_number){
      cout << itr->first <<endl;
    }
  }

}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define fst first
#define snd second
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n,m,r = INF,	res = 0;
	vector<pair<int,int> > a;
	cin >> n >> m;
	a.resize(m);
	REP(i,m) cin >> a[i].fst >> a[i].snd;
	SORT(a.rbegin(), m);
	REP(i,m) if(a[i].snd <= r) res++, r = a[i].fst;
	
	cout << res << "\n";
	
	return 0;
}


Measured memory_bytes: 1024
/*input
3
5 5 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
ll a[maxn];
int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	sort(a,a+n);

	ll ans=0;

	if(n%2){
		REP(i,n/2-1) ans-=2*a[i];
		ans-=a[n/2-1];
		ans-=a[n/2];
		for(int i=n/2+1;i<n;i++) ans+=2*a[i];

		ll cur=0;
		REP(i,n/2) cur-=2*a[i];
		cur+=a[n/2]+a[n/2+1];
		for(int i=n/2+2;i<n;i++) cur+=2*a[i];
		cout<<max(ans,cur)<<'\n';
	//cout<<ans<<' '<<cur<<'\n';
	}
	else{
		REP(i,n/2-1) ans-=2*a[i];
		ans-=a[n/2-1];
		ans+=a[n/2];
		for(int i=n/2+1;i<n;i++) ans+=2*a[i];
		cout<<ans<<'\n';
	}

	return 0;
}


Measured memory_bytes: 1024
n,m = map(int,input().split())

H = list(map(int,input().split()))
d = {}

for i in range(m):
    a,b = map(int,input().split())
    #print(a,b)
    #print(H[a-1],H[b-1])
    if H[a-1] > H[b-1]:
        if (a in d and d[a] == 1) or a not in d:
            d[a] = 1
        if (b in d and d[b] == 1) or b not in d:
            d[b] = 0
    elif H[a-1] < H[b-1]:
        if (b in d and d[b] == 1) or b not in d:
            d[b] = 1
        if (a in d and d[a] == 1) or a not in d:
            d[a] = 0
    else:
        d[a] = 0
        d[b] = 0

c = n - len(d)
#print(d)
for i,j in d.items():
    if j == 1:
        c += 1

print(c)        







Measured memory_bytes: 20024
K, T = map(int, input().split())
A = list(map(int, input().split()))

if T == 1:
    print(A[0] - 1)
    exit()

prev_argmax = -1
for k in range(K):
    if prev_argmax == -1:
        temp_max = -1
        for i, a in enumerate(A):
            if a > temp_max:
                temp_max = a
                argmax = i
    else:
        temp_max = -1
        for i, a in enumerate(A):
            if i != prev_argmax:
                if a > temp_max:
                    temp_max = a
                    argmax = i
        if temp_max == -1:
            temp_max = max(A[:prev_argmax] + A[prev_argmax + 1:])
            for i, a in enumerate(A):
                if i != prev_argmax and a == temp_max:
                    argmax = i
                    break
    if temp_max == 0:
        break
    A[argmax] -= 1
    prev_argmax = argmax
ans = 0
for i, a in enumerate(A):
    if i != prev_argmax:
        ans += max(0, a - 1)
    else:
        ans += max(0, a)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int p[5010];
ll c[5010];
bool flag[5010];
vector<int> v;
ll solve(int x,int n,ll k){
    for(int i=0;i<n;i++) flag[i] = false;
    ll sc = 0,ans = 0; v.clear();
    x = p[x]; ans += c[x]; k--;
    int now = x,cnt = 0;
    while(!flag[p[now]]){
        sc += c[now]; flag[p[now]] = true;
        cnt++; v.push_back(p[now]); now = p[now];
    }
    //cout << x << " " << cnt << " " << sc << endl;
    for(int i=0;i<cnt;i++) v.push_back(v[i]);
    if(sc>0){
        ll r = k%(ll)v.size();
        if(k>v.size()){
            ans += 2*sc*((k - (ll)v.size() - r)/(ll)v.size());
            k = v.size() + r;
        }
        for(int i=0;i<r;i++) v.push_back(v[i]);
        ll ans1 = 0,ans2 = 0;
        for(int i=0;i<k;i++){
            ans1 += c[v[i]]; ans2 = max(ans1,ans2);
        }
        ans += ans2;
    }else{
        ll ans1 = 0,ans2 = 0;
        for(int i=0;i<min(k,(ll)v.size());i++){
            ans1 += c[v[i]]; ans2 = max(ans1,ans2);
        }
        ans += ans2;
    }
    //cout << x << " " << ans << endl;
    return ans;
}

int main(){
    int i,n,k; cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> p[i]; p[i]--;
    }
    for(i=0;i<n;i++) cin >> c[i];
    ll ans = -1000000000000000000;
    for(i=0;i<n;i++){
        ll z = solve(i,n,k);
        ans = max(ans,z);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
#include <cstdio>
#include <cstring>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MaxN = 1e6;
const LL INF = 1LL << 60;

LL h, w;
int main()
{
	while(scanf("%lld %lld", &h, &w) != EOF)
	{
		if(h % 3 == 0 || w % 3 == 0) printf("0\n");
		else
		{
			LL Maxs = 0, Mins = 0;
			LL s1, s2, s3;
			LL ans = 1LL << 60;
			if(h == 2 || w == 2) printf("1\n");
			else
			{
				for(LL i = 1; i <= h; i++)
				{
					s1 = i * w;

					s2 = (h - i) * (w / 2);
					s3 = h * w - s1 - s2;
					Maxs = max(s1, max(s2, s3));
					Mins = min(s1, min(s2, s3));
					ans = min(ans, (Maxs - Mins));

					s2 = (h - i) / 2 * w;
					s3 = h * w - s1 - s2;
					Maxs = max(s1, max(s2, s3));
					Mins = min(s1, min(s2, s3));
					ans = min(ans, (Maxs - Mins));
				}
				for(LL i = 1; i <= w; i++)
				{
					s1 = i * h;

					s2 = (w - i) * (h / 2);
					s3 = h * w - s1 - s2;
					Maxs = max(s1, max(s2, s3));
					Mins = min(s1, min(s2, s3));
					ans = min(ans, (Maxs - Mins));

					s2 = (w - i) / 2 * h;
					s3 = h * w - s1 - s2;
					Maxs = max(s1, max(s2, s3));
					Mins = min(s1, min(s2, s3));
					ans = min(ans, (Maxs - Mins));
				}
				printf("%lld\n", ans);
			}
		}
	}
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
#define all(a) begin(a),end(a)

#define D1(a) cerr<<#a<<":"<<a<<endl
#define D2(a,b) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<endl
#define D3(a,b,c) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl
#define DH(c) do{rep(__i, c.size())cerr<<c[__i]<<(__i==c.size()-1?'\n':' ');}while(0)

int main()
{
    int X, Y, A, B, C; cin >> X >> Y >> A >> B >> C;
    vector<int> P(A), Q(B), R(C); cin >> P >> Q >> R;

    sort(all(P), greater<int>());
    sort(all(Q), greater<int>());
    sort(all(R), greater<int>());

    vector<int> S;
    S.insert(S.end(), P.begin(), P.begin() + X);
    S.insert(S.end(), Q.begin(), Q.begin() + Y);
    S.insert(S.end(), R.begin(), R.begin() + min(X + Y, C));
    // DH(S);
    sort(all(S), greater<int>());
    ll ans = 0;

    rep(i, X+Y) {
        ans += S[i];
    }

    cout << ans << endl;
}


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

int main(){

	string str;

	while(1){

		int sum=0;
		getline(cin,str);

		if(str[0]=='0') break;

		for(int i=0; i<str.size(); i++){
			sum += str[i] - '0';
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1176
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>

int main() {
  char buf[200010];
  scanf("%s", buf);
  std::string s = buf;

  intmax_t res = 0;
  intmax_t b = 0;
  intmax_t w = 0;
  for (char c: s) {
    if (c == 'B') {
      ++b;
    } else if (c == 'W') {
      ++w;
      res += b;
    }
  }
  printf("%jd\n", res);
}


Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
typedef long long ll;
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	int N;
	scanf("%d", &N);
	int x,cnt = 0;
	for (int i = 0; i < N; i++) {
		scanf("%d", &x);
		if (x % 2 == 1)cnt++;
	}
	if (cnt % 2 == 0)printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 256
N,K,Q = input().split()
N = int(N)
K = int(K)
Q = int(Q)

N_point = []

A = []
for i in range(Q):
  A.append(int(input()))

for i in range(N):
  N_point.append(K)

def calc_hiku(n):
    return n - Q

for i in A:
  #N_point = list(map(calc_hiku, N_point))
  N_point[i-1] = int(N_point[i-1]) + 1

N_point = list(map(calc_hiku, N_point))
#N_point_w = list(map(lambda x: x - K, N_point))

for num in N_point:
  if num > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 13740
#include <iostream>
using namespace std;
int main(void){
    
    int N, T;
    cin >> N >> T;
    
    int c[N], t[N];
    for(int i = 0;i < N;i++){
        cin >> c[i] >> t[i];
    }
    
    int ans = 1001;
    for(int i = 0;i < N;i++){
        if(t[i] <= T && c[i] <= ans){
            ans = c[i];
        }
    }
    if(ans == 1001){
        cout << "TLE" << endl;
    }else{
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

ll sum[MAX];

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	memr(sum, 0);
	int n; cin >> n;
	vector<int> v(n);
	rep(i, n) {
		cin >> v[i];
		sum[v[i]]++;
	}
	if(n % 2 == 1) sum[0]++;

	bool ok = true;
	ll all = n-1;
	while(all >= 0){
		if(sum[all] == 2) sum[all] = 0;
		else ok = false;
		all -=2;
	}

	rep(i, MAX){
		if(sum[i] != 0) ok = false;
	}

	if(!ok){
		cout << 0 << endl;
	}
	else{
		ll ans = 1;
		rep(i, n / 2){
			ans *= 2;
			ans %= MOD;
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 4420
#include <stdio.h>
#include <math.h> 
int main() {
  int n;
  scanf("%d", &n);
  long long a[n];
  for(int i=0;i<n;i++) {
    scanf("%lld", &a[i]);
    if(a[i]==0){
      printf("0");
      return 0;
    }
  }
  long long ans=1;
  for(int i=0;i<n;i++){
    if(log10(ans)+log10(a[i])>18){
      printf("-1");
      return 0;
    }
    ans *= a[i];
    if(ans > 1000000000000000000){
      printf("-1");
      return 0;
    }
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 3148