akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

int main(){
  while(1){
    string str;
    cin >> str;
    if(str=="#") break;

    vector<int> seq(str.length());
    for(int i=0; i<(int)str.length(); i++){
      seq[i] = (str[i]-'0'+2)%3;
    }

    int leg=-1;
    int count=0;
    for(int i=1; i<(int)str.length(); i++){
      if(seq[i]==seq[i-1]){
        if(leg!=-1){
          leg = 1-leg;
        }
      }else if(seq[i]-seq[i-1]>0){ //to right
        if(leg==1){
          count++;
        }else if(leg==0){
          leg=1;
        }else{
          leg=1;
        }
      }else{
        if(leg==0){
          count++;
        }else if(leg==1){
          leg = 0;
        }else{
          leg = 0;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

#define int ll

int n;

signed main(){
    cin>>n;
    vint p(n);
    vint a(n);
    vint b(n);
    rep(i,0,n)cin>>p[i],p[i]--;
    rep(i,0,n)a[i]=1+i*30000;
    rep(i,0,n)b[n-i-1]=1+i*30000;
    rep(i,0,n)a[p[i]]+=i;
    rep(i,0,n)cout<<a[i]<<" ";
    cout<<endl;
    rep(i,0,n)cout<<b[i]<<" ";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 896
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author naruse
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        HonestOrUnkind2 solver = new HonestOrUnkind2();
        solver.solve(1, in, out);
        out.close();
    }

    static class HonestOrUnkind2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a[][] = new int[n][n];
            for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) a[i][j] = -1;
            for (int i = 0; i < n; i++) {
                int k = in.nextInt();
                for (int j = 0; j < k; j++) {
                    int x = in.nextInt();
                    int y = in.nextInt();
                    x--;
                    a[i][x] = y;
                }
            }
            int ans = 0;
            for (int i = 0; i < (1 << n); i++) {
                boolean ok = true;
                for (int j = 0; j < n; j++) {
                    int now = (i >> j) % 2;
                    for (int k = 0; k < n; k++) {
                        if (a[j][k] == -1) continue;
                        if (now == 0) {
                            //
                        } else {
                            if (a[j][k] == 1 && (i >> k) % 2 == 0) {
                                ok = false;
                            } else if (a[j][k] == 0 && (i >> k) % 2 == 1) {
                                ok = false;
                            }
                        }
                    }
                    if (!ok) break;
                }
                if (ok) {
                    int cnt = 0;
                    for (int j = 0; j < n; j++) {
                        if ((i >> j) % 2 == 1) cnt++;
                    }
                    ans = Math.max(ans, cnt);
                }
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 24404
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
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();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
	int n;
	cin>>n;
	REP(i,n){
		int b[3]={};
		int score=0;
		int out=0;
		while(1){
			string s;
			cin>>s;
			if(s=="HIT"){
				score+=b[2];
				for(int j=2;j>0;j--){
					b[j]=b[j-1];
				}
				b[0]=1;
			}else if(s=="HOMERUN"){
				REP(j,3){
					score+=b[j];
					b[j]=0;
				}
				score++;
			}else if(s=="OUT"){
				out++;
				if(out==3){
					goto end;
				}
			}
		}
end:
		cout<<score<<endl;
	}
}

Measured memory_bytes: 1212
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn main(){
    let mut n = read_as_vec::<i64>()[0];
    let mut bit: i64 = 1;
    let mut res: Vec<bool> = vec![];

    if n == 0{
        println!("0");
        return;
    }

    while n != 0{
        if n%(bit*-2) == 0{

            res.push(false);
        }else{
            res.push(true);
            n -= bit;
        }
        bit *= -2;
    }

    for b in res.into_iter().rev(){
        if b{
            print!("1");
        }else{
            print!("0");
        }
    }
    println!("");
}


Measured memory_bytes: 4352
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val N  = rd.readInt()
    val A = rd.readLongArray()
    val B = rd.readLongArray()

    if (A.joinToString("") == B.joinToString("")) {
        println("Yes")
        return
    }

    val ASum = A.sum()
    val BSum = B.sum()
    if (ASum > BSum) {
        println("No")
        return
    }

    var bOp = 0L
    for (i in 0 until N) {
        if (A[i] < B[i]) {
            bOp += (B[i] - A[i])/2
        } else if (A[i] > B[i]) {
            bOp -= (A[i] - B[i])
        }
    }

    val ans = if (bOp >= 0) "Yes"
                    else "No"

    println(ans)
}


//val rd = debug.Reader("etc", "apc001", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!! }
    catch (e: Exception) { throw e }
    finally { rd.close() }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
    val readListIntCol: (Int) -> List<Int> = { N -> (0 until N).map { readInt() } }
    val readListLongCol: (Int) -> List<Long> = { N -> (0 until N).map { readLong() } }
    val close: () -> Unit = { br.close() }
    protected fun finalize() { close() }
}


Measured memory_bytes: 47696
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i=0; i<N; i++) {
            a[i] = sc.nextInt();
        }

        int[] ans = solve(N, a);

        for (int i=0; i<N; i++) {
            System.out.println(ans[i]);
        }
    }

    private static int[] solve(int N, int[] a) {
        int[] ans = new int[N];
        int total = Math.abs(a[0]) + Math.abs(a[N-1]);

        for (int i=0; i<N-1; i++) {
            total += Math.abs(a[i+1] - a[i]);
        }

        for (int i=0; i<N; i++) {
            ans[i] = total;

            if (i == 0) {
                if (0 <= a[i] && a[i] <= a[i+1]
                        || a[i+1] <= a[i] && a[i] <= 0) {
//                    System.err.println("ans[" + i + "] : skip");
                    continue;
                }
                ans[i] = total - Math.abs(a[i] - 0) - Math.abs(a[i] - a[i+1]) + Math.abs(a[i+1] - 0);
//                System.err.println("ans[" + i + "] = " + ans[i]);
            } else if (i == N-1) {
                if (0 <= a[i] && a[i] <= a[i-1]
                        || a[i-1] <= a[i] && a[i] <= 0) {
//                    System.err.println("ans[" + i + "] : skip");
                    continue;
                }

                ans[i] = total - Math.abs(a[i] - 0) - Math.abs(a[i] - a[i-1]) + Math.abs(a[i-1] - 0);
//                System.err.println("ans[" + i + "] = " + ans[i]);
            }
            else if (a[i-1] <= a[i] && a[i] <= a[i+1]
                    || a[i+1] <= a[i] && a[i] < a[i-1]) {
//                System.err.println("ans[" + i + "] : skip");
                continue;
            } else {
                ans[i] = total - Math.abs(a[i] - a[i-1]) - Math.abs(a[i] - a[i+1]) + Math.abs(a[i+1] - a[i-1]);
//                System.err.println("ans[" + i + "] = " + ans[i]);
            }
        }

        return ans;
    }
}

Measured memory_bytes: 69064
/*
10 3
4 5 6
*/
#include <bits/stdc++.h>
using namespace std;
void print() { cout << '\n'; } template<class T, class ...U> void print(T x, U ...y) { cout << x << ' '; print(y...); }
typedef long long ll; const int N = 2e5 + 5, M = 1e9 + 7; typedef vector<int> vi; typedef vector<vi> vii; void Main();
int main(int argc, char **argv) {
  ios::sync_with_stdio(0), cin.tie(0); cout << setprecision(10) << fixed;
  #ifdef Zmm
  freopen((string(*(argv)).substr(2, string(*(argv)).size() - 6) + string(".cpp")).c_str(), "r", stdin); string x; cin >> x;
  #endif
  Main();
}
int a[N];
void Main() {
  int H, n;
  ll sum = 0;
  cin >> H >> n;
  for (int i = 0; i < n; i++) cin >> a[i], sum += a[i];
  cout << (sum >= H ? "Yes\n" : "No\n");

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9;

int main(){
    int N;  cin >> N;
    vector<int> P(N), Q(N);
    for(int i=0; i<N; i++) cin >> P[i];
    for(int i=0; i<N; i++) cin >> Q[i];

    vector<int> Order(N);
    for(int i=0; i<N; i++) Order[i] = i+1;
    int p=0, q=0;
    int cnt = 0;
    do {
        cnt++;
        bool pflag = true, qflag = true;
        for(int i=0; i<N; i++){
            if(Order[i] != P[i]) pflag = false;
            if(Order[i] != Q[i]) qflag = false;
        }
        if(pflag) p = cnt;
        if(qflag) q = cnt;
    }while(next_permutation(Order.begin(), Order.end()));

    cout << abs(p-q) << endl;
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

res = 0
for i in range(N):
    for j in range(i + 1, N - 1):
        for k in range(j + 1, N):
            if L[i] != L[j] and L[j] != L[k] and L[i] != L[k]:
                if L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
                    res += 1

print(res)


Measured memory_bytes: 9024
# -*- coding: utf-8 -*- 
### 数値　a b c をスペース区切りで読み込み
### c の約数がa<=b の間にいくつあるかを表示する。

#数値入力・変換
str_in = raw_input()
int_in = map(int, str_in.split())

# a〜bの約数の数を求める
counter = 0
for i in range(int_in[0], int_in[1]+1):
	if int_in[2] % i == 0:
		counter = counter + 1
		
# 個数を表示する。
print(counter)



Measured memory_bytes: 4812
#include<bits/stdc++.h>
using namespace std;
int n,ans;
int a[25];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=2;i<n;i++){
		if(a[i]>a[i-1]&&a[i]<a[i+1]) ans++;
		if(a[i]<a[i-1]&&a[i]>a[i+1]) ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <stdlib.h>
#include <algorithm>
#include <functional>
 
using namespace std;
 
int main(void) {
	unsigned long int a = 0;
	string S;
	cin >> a;
	cin >> S;
    
    if(a >= 3200){
        cout << S << endl;
    }
    else{
        cout << "red" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define vb vector<bool>
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vector<int>>
#define ii pair<int, int>
#define lower_str(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define upper_str(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define debug(index, num) cout << "Case #" << index << ": " << num << endl
#define mx(an, na) an = max(an, na)
#define mn(an, na) an = min(an, na)
#define rep(i, a, b) for (long long i = a; i < b; i++)
#define rep2(i, a, b) for (long long i = a; i <= b; i++)
#define repp(i, a, b) for (long long i = a; i >= b; i--)
#define repp2(i, a, b) for (long long i = a - 1; i >= b; i--)
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    vector<vector<char>> v(n+2, vector<char> (m+2, '#'));
    ll maxi = 0;
    int f = 4;
    rep2(i, 1, n) {
        rep2(j, 1, m) {
            cin >> v[i][j];
        }
    }
    vector<ii> g = {{1, 1}, { 1, m}, { n, m}, {n ,1}};
    rep2(i, 1, n) {
        rep2(j, 1, m) {

            queue<pair<ii, ll>> bfs;
            vector<vector<bool>> vis(n+2, vb(m+2, 0));
            rep2(k, 0, n+1) {
                vis[k][0] = 1;
                vis[k][m+1] = 1;
            }
            rep2(k, 0, m+1) {
                vis[0][k] = 1;
                vis[n+1][k] = 1;
            }
            // cout << "time number " << f << endl;
            if(v[i][j] == '#') continue;
            bfs.push({{i, j}, 0});
            vis[i][j] = 1;
            while(!bfs.empty()) {
                int id = bfs.front().first.first;
                int jd = bfs.front().first.second;
                // cout << i << " " << j << " " << bfs.front().second << endl;
                if(v[id][jd+1] == '.' && !vis[id][jd+1]){ bfs.push({{id, jd+1}, bfs.front().second + 1}); vis[id][jd+1] = 1;}
                if(v[id][jd-1] == '.' && !vis[id][jd-1]){ bfs.push({{id, jd-1}, bfs.front().second + 1}); vis[id][jd-1] = 1;}
                if(v[id+1][jd] == '.' && !vis[id+1][jd]){ bfs.push({{id+1, jd}, bfs.front().second + 1}); vis[id+1][jd] = 1;}
                if(v[id-1][jd] == '.' && !vis[id-1][jd]){ bfs.push({{id-1, jd}, bfs.front().second + 1}); vis[id-1][jd] = 1;}
                maxi = max(maxi, bfs.front().second);
                bfs.pop();
            }
        }
    }
    cout << maxi;
} 

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

#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
  int i, j, k, l;
  int flag = 1;
  std::string S;
  std::cin >> S;
  for(i = 0;i < S.size();i++) {
    flag = 1;
    if(i % 2) {
      if(S[i] != 'i') {
        puts("No");
        return 0;
      }
    } else {
      flag = 0;
      if(S[i] != 'h') {
        puts("No");
        return 0;
      }
    }
  }
  if(flag) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.lang.Math;

public class Main {
	int[] a;
	int n;

	public boolean isNonNegativeInteger() {
		for(int i = 0; i < n; i++) {
			if(a[i] <= 0) {
				return false;
			}
		}
		return true;
	}

	public boolean isNegativeInteger() {
		for(int i = 0; i < n; i++) {
			if(a[i] > 0) {
				return false;
			}
		}
		return true;
	}

	public int max() {
		int max = Integer.MIN_VALUE / 2;
		int index = -1;
		for(int i = 0; i < n; i++) {
			if(max < a[i]) {
				max = a[i];
				index = i;
			}
		}
		return index;
	}

	public int min() {
		int min = Integer.MAX_VALUE / 2;
		int index = -1;
		for(int i = 0; i < n; i++) {
			if(a[i] < min) {
				min = a[i];
				index = i;
			}
		}
		return index;
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		if(isNonNegativeInteger()) {
			System.out.println(n - 1);
			for(int i = 0; i < n - 1; i++) {
				System.out.println((i + 1) + " " + (i + 2));
				a[i + 1] += a[i];
			}
		}
		else if(isNegativeInteger()) {
			System.out.println(n - 1);
			for(int i = n - 2; i >= 0; i--) {
				System.out.println((i + 2) + " " + (i + 1));
				a[i] += a[i + 1];
			}
		}
		else {
			System.out.println(n + (n - 1));
			int max = max();
			int min = min();
			if(Math.abs(a[max]) >= Math.abs(a[min])) {
				int maxv = a[max];
				for(int i = 0; i < n; i++) {
					System.out.println((max + 1) + " " + (i + 1));
					a[i] += maxv;
				}
				for(int i = 0; i < n - 1; i++) {
					System.out.println((i + 1) + " " + (i + 2));
					a[i + 1] += a[i];
				}
			}
			else {
				int minv = a[min];
				for(int i = 0; i < n; i++) {
					System.out.println((min + 1) + " " + (i + 1));
					a[i] += minv;
				}
				for(int i = n - 2; i >= 0; i--) {
					System.out.println((i + 2) + " " + (i + 1));
					a[i] += a[i + 1];
				}
			}
		}

		// System.out.println(Arrays.toString(a));
	}

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


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N;
	int  K;
	cin >> N >> K;
	vector<int>D(K);
	for (auto &i : D)cin >> i;
	while (1) {
		int n = N;
		bool flag = false;
		while (n) {
			rep(i, K) {
				if (n % 10 == D[i]) {
					flag = true;
					break;
				}
			}
			if (flag)break;
			n /= 10;
		}
		if (!flag) {
			cout << N << endl;
			return 0;
		}
		N++;
	}
	return 0;
}

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class AABCSwap {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int x, y, z; cin >> x >> y >> z;
      swap(x, y);
      swap(x, z);
      cout << x << ' ' << y << ' ' << z << endl;
    }
};

signed main() {
  AABCSwap solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,m,u,v,lab[N],vis[N],val,eg;
ll c[N],ret;
vector<PII> e[N];
void dfs(int u,int d) {
	vis[u]=1; lab[u]=d; c[d]++;
	for (auto p:e[u]) {
		int v=p.fi; eg++;
		if (vis[v]) {
			val&=(lab[v]==(d+p.se)%3);
		} else {
			dfs(v,(d+p.se)%3);
		}
	}
}
int g[110][110];
int main() {
	scanf("%d%d",&n,&m);
//	while (1) {
//	n=5,m=5;
//	rep(i,1,n+1) e[i].clear(),vis[i]=0;
//	rep(i,1,n+1) rep(j,1,n+1) g[i][j]=0;
	rep(i,0,m) {
		scanf("%d%d",&u,&v);
//		u=rand()%n+1,v=rand()%n+1;
//		if (g[u][v]==1) continue;
		e[u].pb(mp(v,1)); e[v].pb(mp(u,2));
//		g[u][v]=1;
//		printf("%d %d\n",u,v);
	}
/*	while (1) {
		bool val=0;
		rep(p,1,n+1) rep(q,1,n+1) rep(r,1,n+1) if (g[p][q]&&g[q][r]&&!g[r][p]) {
			g[r][p]=1; val=1;
		}
		if (!val) break;
	}
	int cnt=0;
	rep(p,1,n+1) rep(q,1,n+1) cnt+=g[p][q];
	printf("%d\n",cnt);*/
	ret=0;
	rep(i,1,n+1) if (!vis[i]) {
		c[0]=c[1]=c[2]=0;
		val=1; eg=0;
		dfs(i,0);
		if (val) {
			if (c[2]&&c[1]) ret+=c[0]*c[1]+c[1]*c[2]+c[2]*c[0];
			else ret+=eg/2;
		} else ret+=(c[0]+c[1]+c[2])*(c[0]+c[1]+c[2]);
	}
	printf("%lld\n",ret);
	//assert(ret==cnt);
//}
}


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

int main(){
    int n;

    int a[200010];

    cin >> n;

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

    int b[200010] = {};

    for(int i = n;i >= 1;i--){

        int cnt = 0;
        for(int j = i*2;j <= n;j+=i){
            cnt += b[j];
        }

        if(cnt % 2 != a[i]){
            b[i] = 1;
        }else{
            b[i] = 0;
        }
    }

    queue<int> que;
    for(int i = 1;i <= n;i++){
        if(b[i] == 1){
            que.push(i);
        }
    }

    cout << que.size() << endl;

    while(!que.empty()){
        cout << que.front();
        que.pop();
        if(que.empty()){
            cout << endl;
        }else{
            cout << " ";
        }
    }

    return 0;
}



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

int main(){
    string a, b;
    cin >> a >> b;
    if ((a == "H" && b=="H") || (a=="D" && b=="D")){
        cout << "H" << endl;
    }else if ((a == "D" && b=="H") || (a=="H" && b=="D")){
        cout << "D" << endl;
    }
    
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val s = readLine()!!
    if (s.first() == s.last()) {
        if (s.length % 2 == 0) {
            println("First")
        } else {
            println("Second")
        }
    } else {
        if (s.length % 2 == 1) {
            println("First")
        } else {
            println("Second")
        }
    }
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 33832
a = [[0] * 3 for i in range(3)]
for i in range(3):
    a[i] = list(map(int, input().split()))

n = int(input())

b = [0] * n
for i in range(n):
    b[i] = int(input())

arr = [[0] * 3 for i in range(3)]
for i in range(n):
    for x in range(3):
        for y in range(3):
            if a[x][y] == b[i]:
                arr[x][y] = 1
flag = False
for x in range(3):
    count = 0
    for y in range(3):
        count += arr[x][y]
    if count == 3:
        flag = True

for x in range(3):
    count = 0
    for y in range(3):
        count += arr[y][x]
    if count == 3:
        flag = True

if arr[0][0] + arr[1][1] + arr[2][2] == 3:
    flag = True

if arr[0][2] + arr[1][1] + arr[2][0] == 3:
    flag = True

if flag:
    print('Yes')
else:
    print('No')


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

int main(){
   int n,m;
   cin >> n>>m;
   auto x = vector<int>(m,0);
   for (int i = 0; i < m; i++)
   {
       cin >> x[i];
   }

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

    if(n>=m){
        cout << 0;
    }else{
        auto dist = vector<int>(m-1,0);
        for (int i = 0; i < m-1; i++)
        {
            dist[i] = x[i+1] - x[i];
        }
        sort(dist.begin(),dist.end());
        auto sum = accumulate(dist.begin(),prev(dist.end(),n-1),0);
        cout << sum;
    }

}

Measured memory_bytes: 1024
A=(1..3).map{|i| gets.split.map{|j| j.to_i}}

N=gets.to_i

for i in (1..N)
    b=gets.to_i
    for j in (0..2)
        for k in (0..2)
            if A[j][k]==b
                A[j][k]=0
            end
        end
    end
end


for i in (0..2)
    if A[i].inject(:+)==0
        puts "Yes"
        exit
    end
    
    if (0..2).map{|j| A[j][i]}.inject(:+)==0
        puts "Yes"
        exit
    end

end

if (0..2).map{|i| A[i][i]}.inject(:+)==0
    puts "Yes"
    exit
end

if (0..2).map{|i| A[i][2-i]}.inject(:+)==0
    puts "Yes"
    exit
end

puts "No"

Measured memory_bytes: 3836
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
//#define MAX 300000
int main()
{
	int i;
	int max, count1, count2;
	int num1[26], num2[26], n;
	char s[105];
	while(scanf("%d", &n) != EOF){
		max = count1 = count2 = 0;
		for (i = 0; i < 26; i++)
			num1[i] = num2[i] = 0;
		scanf("%s", s);
		for (i = 0; i < n; i++){
			num2[s[i] - 'a']++;
		}
		for (i = 0; i < 26; i++)
			if(num2[s[i] - 'a'])
				count2++;
		
		for (i = 0; i < n; i++){
			if(num1[s[i] - 'a'] == 0 && num2[s[i] - 'a'] > 1){
				count1++;
			}else if(num1[s[i] - 'a'] > 0 && num2[s[i] - 'a'] == 1){
				count1--;
			}
			if(max < count1)
				max = count1;
			num2[s[i] - 'a']--;
			num1[s[i] - 'a']++;
		}
		
		printf("%d\n", max);
	}
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define all(v) (v).begin(),(v).end()
typedef long long LL;
typedef pair<LL, LL> PL;

LL gcd(LL a, LL b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	string str;
	while (cin >> str, str != "#"){
		vector<string> vs;
		vs.PB(str);
		
		while (true){
			int p = vs.size() - 1;
			if (vs[p].size() > 5){
				if (vs[p][0] == 'n'){
					string a(vs[p], 0, 5);
					string b(vs[p], 5, vs[p].size() - 5);
					vs[p] = a;
					vs.PB(b);
				}
				else {
					string a(vs[p], 0, 4);
					string b(vs[p], 4, vs[p].size() - 4);
					vs[p] = a;
					vs.PB(b);
				}
			}
			else break;
		}
		
		reverse(all(vs));
		
		for (int i = 0; i < vs.size(); i++){
			//cout << vs[i] << endl;
		}
		
		PL p = PL(0LL, 0LL);
		for (int i = 0; i < vs.size(); i++){
			if (vs[i] == "north"){
				if (i) p.first = p.first * 2 - 90;
			}
			else {
				p.first = p.first * 2 + 90;
			}
			if (p.second == 0){
				p.second = 1;
			}
			else {
				p.second *= 2;
			}
		}
		
		if (p.first % p.second == 0LL){
			cout << p.first / p.second << endl;
		}
		else {
			LL g = __gcd(abs(p.first), p.second);
			p.first /= g;
			p.second /= g;
			cout << p.first << "/" << p.second << endl;
		}
	}
	
	return 0;
}

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


int main() {
    ll N, M;

    cin >> N >> M;

    ll sum = 0;
    ll num = 0;

    vector<int> A(N);

    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
        sum += A.at(i);
    }
    

    string ans = "Yes";

    long double tmp1 = 0;
    long double tmp2 = 0;

    for (int i = 0; i < N; i++) {

        tmp1 = 1/(4*(double)M);
        tmp2 = (double)A.at(i)/(double)sum;

        if (tmp2 >= tmp1) {
            num += 1;
        }
    }
    if (num < M) {
        ans = "No";
    }
    
    


    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, M;
int A[100000], B[100000], S[100000];
vector<pair<int,ll>> e[100000];

int vis[100000];
ll x[100000];

bool dfs1(int n, int p, int d){
    vis[n] = d;
    if(d == 0 && x[n] <= 0) return false;
    bool ret = true;
    rep(i, e[n].size()){
        if(vis[e[n][i].first] == d){
            if(d == 0 && x[n]+x[e[n][i].first] < e[n][i].second){
                return false;
            }
            if(d == 1 && x[n]+x[e[n][i].first] > e[n][i].second){
                return false;
            }
            continue;
        }
        if(vis[e[n][i].first] == (d^1)){
            if(x[n]+x[e[n][i].first] != e[n][i].second){
                cout << 0 << endl;
                exit(0);
            }
            continue;
        }
        x[e[n][i].first] = e[n][i].second-x[n];
        ret &= dfs1(e[n][i].first, n, d^1);
    }
    return ret;
}

bool dfs2(int n, int p, int d){
    vis[n] = d;
    if(d == 1 && x[n] <= 0) return true;
    bool ret = false;
    rep(i, e[n].size()){
        if(vis[e[n][i].first] == d){
            if(d == 0 && x[n]+x[e[n][i].first] > e[n][i].second){
                return true;
            }
            if(d == 1 && x[n]+x[e[n][i].first] < e[n][i].second){
                return true;
            }
            continue;
        }
        if(vis[e[n][i].first] == (d^1)){
            if(x[n]+x[e[n][i].first] != e[n][i].second){
                cout << 0 << endl;
                exit(0);
            }
            continue;
        }
        x[e[n][i].first] = e[n][i].second-x[n];
        ret |= dfs2(e[n][i].first, n, d^1);
    }
    return ret;
}

signed main(){
    cin >> N >> M;
    rep(i, M){
        cin >> A[i] >> B[i] >> S[i];
        A[i]--; B[i]--;
        e[A[i]].pb({ B[i],S[i] });
        e[B[i]].pb({ A[i],S[i] });
    }
    
    ll ng1 = 0;
    ll ok1 = 1e15L;
    while(ok1-ng1 > 1){
        ll m = (ok1+ng1)/2;
        memset(vis, -1, sizeof(vis));
        x[0] = m;
        if(dfs1(0, -1, 0)) ok1 = m;
        else ng1 = m;
    }

    ll ng2 = 0;
    ll ok2 = 1e15L;
    while(ok2-ng2 > 1){
        ll m = (ok2+ng2)/2;
        memset(vis, -1, sizeof(vis));
        x[0] = m;
        if(dfs2(0, -1, 0)) ok2 = m;
        else ng2 = m;
    }

    //cout << ok1 << " " << ok2 << endl;
    cout << max(0LL, ok2 - ok1) << endl;
}

Measured memory_bytes: 21284
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

const int MAXN = 1000 + 10;

#define y1 MyY1
#define y2 MyY2
struct barrier
{
    int x, y, r;
};

int N;
int x1, x2, y1, y2;
vector <barrier> vbar;
double dist[MAXN];
bool inQueue[MAXN];

double precalcDist[MAXN][MAXN];
double getDist(int from, int to)
{
    double deltaX = vbar[from].x - vbar[to].x;
    double deltaY = vbar[from].y - vbar[to].y;
    return max(sqrt(deltaX * deltaX + deltaY * deltaY) - vbar[from].r - vbar[to].r, 0.0);
}

void SPFA()
{
    fill(dist, dist + N + 2, 1e100);
    memset(inQueue, 0x00, sizeof inQueue);

    queue <int> q;
    q.push(0);
    dist[0] = 0, inQueue[0] = true;

    while(!q.empty())
    {
        int to = q.front();
        inQueue[to] = false;
        q.pop();

        for(int i = 0; i <= N + 1; i++)
        {
            if(i == to)
                continue;

            if(dist[i] > dist[to] + precalcDist[i][to])
            {
                dist[i] = dist[to] + precalcDist[i][to];
                if(!inQueue[i])
                {
                    inQueue[i] = true;
                    q.push(i);
                }
            }
        }
    }
}

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

    int u, v, w;

    cin >> x1 >> y1 >> x2 >> y2 ;
    vbar.push_back(barrier{x1, y1, 0});
    vbar.push_back(barrier{x2, y2, 0});

    cin >> N ;
    for(int i = 1; i <= N; i++)
        cin >> u >> v >> w, vbar.push_back(barrier{u, v, w});

    for(int i = 0; i <= N + 1; i++)
        for(int j = 0; j < i; j++)
            precalcDist[i][j] = precalcDist[j][i] = getDist(i, j);

    SPFA();

    cout << fixed << setprecision(10) << dist[1] << endl ;

    return 0;
}


Measured memory_bytes: 8192
n=int(input())
for i in range(n):
    s0,s1=map(str,input().split())
    ans=""
    ans0=0
    ans1=0
    ans2=0
    p=1
    for j in range(len(s0)):
        if s0[j]!="m" and s0[j]!="c" and s0[j]!="x" and s0[j]!="i" :
            p=int(s0[j])
            continue
        if s0[j]=="m":
            ans0+=p*1000
            p=1 
        if s0[j]=="c":
            ans0+=p*100
            p=1
        if s0[j]=="x":
            ans0+=p*10
            p=1
        if s0[j]=="i":
            ans0+=p*1
            p=1
    for k in range(len(s1)):
        if s1[k]!="m" and s1[k]!="c" and s1[k]!="x" and s1[k]!="i" :
            p=int(s1[k])
            continue
        if s1[k]=="m":
            ans1+=p*1000 
            p=1
        if s1[k]=="c":
            ans1+=p*100
            p=1
        if s1[k]=="x":
            ans1+=p*10
            p=1
        if s1[k]=="i":
            ans1+=p*1
            p=1
    ans2=ans0+ans1
    while ans2>0:
        if ans2>=1000:
            sans2=str(ans2)
            if sans2[0]=="1":
                ans=ans+"m"
            else:
                ans=ans+sans2[0]+"m"
            ans2=int(sans2[1:])
            continue
        if ans2>=100:
            sans2=str(ans2)
            if sans2[0]=="1":
                ans=ans+"c"
            else:
                ans=ans+sans2[0]+"c"
            ans2=int(sans2[1:])
            continue
        if ans2>=10:
            sans2=str(ans2)
            if sans2[0]=="1":
                ans=ans+"x"
            else:
                ans=ans+sans2[0]+"x"
            ans2=int(sans2[1:])
            continue
        if ans2>=1:
            sans2=str(ans2)
            if sans2[0]=="1":
                ans=ans+"i"
            else:
                ans=ans+sans2[0]+"i"
            break
    print(ans)


Measured memory_bytes: 5632
#include <iostream>
#include <algorithm>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
#define REP(i, a, b) for(i = a; i < b; i++)
using namespace std;

int INF = 1e+15;
int n, c;
int h[200000];
int dp[200000];

int cal(int i, int j) { return dp[i] + (h[i] - h[j]) * (h[i] - h[j]) + c; }

void calc(int l1, int r1, int l2, int r2) {
	if (l2 >= r2) return;
	int m = (l2 + r2) / 2;
	int i;
	
	int it = l1;
	REP(i, l1, r1) {
		if (cal(i, m) < cal(it, m)) {
			it = i;
		}
	}
	dp[m] = min(dp[m], cal(it, m));
	calc(l1, it + 1, l2, m);
	calc(it, r1, m + 1, r2);
}

void solve(int l, int r) {
	if (r - l <= 1) return;
	int m = (l + r) / 2;
	solve(l, m);
	calc(l, m, m, r);
	solve(m, r);
}

signed main() {
	int i;
	
	cin >> n >> c;
	rep(i, n) cin >> h[i];
	rep(i, n) dp[i] = INF;
	dp[0] = 0;
	solve(0, n);
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <ctype.h>

int main(){
    int i, c;
    int count[26] = { 0 };
    
    while((c = getchar()) != EOF){
        if(isalpha(c)){
            if(isupper(c)){
                c = tolower(c);
            }
            
            ++count[c - 'a'];
        }
    }
    
    for(i = 0; i < 26; ++i){
        printf("%c : %d\n", 'a' + i, count[i]);
    }
    
    return 0;
}

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

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

using namespace std;

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

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

void solve() {
  string s;
  cin >> s;
  int n = s.size();
  vi32 cost(n + 1);
  rep(i, n) {
    if (s[i] == '<') amax(cost[i + 1], cost[i] + 1);
  }
  rrep(i, n) {
    if (s[i] == '>') amax(cost[i], cost[i + 1] + 1);
  }
  i64 ans = 0;
  repc(i, n) ans += cost[i];
  cout << ans << endl;
}


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

int main(){
  int N;
  vector<int64_t> X(100010), L(100010);

  vector<pair<int64_t, int64_t>> interval;

  cin >> N;
  for(int i=0; i<N; i++){
    cin >> X[i] >> L[i];
    interval.push_back(make_pair(X[i]+L[i], X[i]-L[i]));
  }

  sort(interval.begin(), interval.end());

  int ans = 0; int64_t x = -999999999;
  for(int i=0; i<N; i++){
    if(x <= interval[i].second){
      ans++; x = interval[i].first;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4464
#include <iostream>
#include <cassert>
#include <limits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <array>
#include <map>
#include <set>
#include <deque>
#include <list>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>
#include <bitset>
#include <stack>
#include <queue>

#define MOD (1e9 + 7);
#define PI (3.14159265358979323846)

using ll = int64_t;
using ull = uint64_t;

using namespace std;

[[maybe_unused]] static auto __x = [](){ios_base::sync_with_stdio(0); cin.tie(0);};

int main() {
    int a;
    cin >> a;
    cout << (int)(a*a);

    return 0;
}


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

primes = [1] * (55555+1)
primes[0] = 0
primes[1] = 0
for i in range(len(primes)):
    if primes[i] == 0: continue
    pi = i*2
    while pi <= 55555:
        primes[pi] = 0
        pi += i

ans = []
for i, p in enumerate(primes):
    if i % 5 == 1 and p:
        ans.append(i)

print(" ".join(map(str, ans[0:N])))

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int m[3][3];
int main() {
	int a, b, c; scanf("%d%d%d", &a, &b, &c);
	int d, e;
	m[0][0] = a;
	m[0][1] = b;
	m[1][1] = c;
	for (int i = -10000;i<=10000; i++) {
		d = m[2][2] = i;
		e = m[0][2] = i + c - b;
		int s = a + b + e;
		int f = m[1][2] = s - d - e;
		int g = m[2][1] = s - b - c;
		int h = m[2][0] = s - d - g;
		m[1][0] = s - a - h;
		bool flag = true;
		rep(j, 3) {
			int sum = 0;
			rep(k, 3) {
				sum += m[j][k];
			}
			if (sum != s)flag = false;
			sum = 0;
			rep(k, 3) {
				sum += m[k][j];
			}
			if (sum != s)flag = false;
		}
		if (m[0][0] + m[1][1] + m[2][2] != s)flag = false;
		if (m[0][2] + m[1][1] + m[2][0] != s)flag = false;
		if (flag)goto g;
	}
	for (int i = -10000;i<=10000; i++) {
		d = m[2][2] = i + b - c;
		e = m[0][2] = i;
		int s = a + b + e;
		int f = m[1][2] = s - d - e;
		int g = m[2][1] = s - b - c;
		int h = m[2][0] = s - d - g;
		m[1][0] = s - a - h;
		bool flag = true;

		rep(j, 3) {
			int sum = 0;
			rep(k, 3) {
				sum += m[j][k];
			}
			if (sum != s)flag = false;
			sum = 0;
			rep(k, 3) {
				sum += m[k][j];
			}
			if (sum != s)flag = false;
		}
		if (m[0][0] + m[1][1] + m[2][2] != s)flag = false;
		if (m[0][2] + m[1][1] + m[2][0] != s)flag = false;
		if (flag)break;
	}
g:;
	rep(i, 3) {
		rep(j, 3) {
			if (j)printf(" ");
			printf("%d", m[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 384
N,M = map(int,(input().split()))
a = [[0]*2 for _ in range(N)]
for i in range(N):
    a[i][0],a[i][1] = map(int,(input().split()))

a.sort()

c = 0
i = 0
p = 0
while c < M: 
    c += 1
    if a[i][1]:
        p += a[i][0]
        a[i][1] -= 1
    else:
        i += 1
        p += a[i][0]
        a[i][1] -= 1

print(p)

Measured memory_bytes: 55308
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  string S;cin>>S;
  int ans = 0,x = 0;
  repeat(i,N){
    x += S[i]=='I'? 1:-1;
    ans = max(ans,x);
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
    string s;

    getline(cin,s);
    int sz = s.size();
    for(int i =0; i<sz; i++)
    {
        if(s[i] == ',')
        {
            s[i] = ' ';
        }
    }
    cout <<s <<endl;
}


Measured memory_bytes: 256
n,m,c = [int(i) for i in input().split()]
b = list(map(int,input().split()))
count = 0
for i in range(n):
    a = list(map(int,input().split()))
    score = 0
    for i in range(m):
        x = a[i]
        score += x * b[i]
    score += c
    if score > 0:
        count+=1

print(count)

Measured memory_bytes: 3064
MAX =20000001
VMAX = 10001
INF = 10 ** 10
cnt = 0

def CountingSort(A, n):
    B = [0 for x in range(n)]
    C = [0 for x in range(VMAX)]
    # C[i] に i の出現数を記録する
    for j in range(n):
        C[A[j]] += 1

     #  C[i] に i 以下の数の出現数を記録する
    for i in range(VMAX):
        C[i] = C[i] + C[i-1]

    for j in range(n):
        B[C[A[j]] -1] = A[j] 
        C[A[j]] -= 1
    print(*B)


n = int(input())
A =[int(x) for x in input().split()]
CountingSort(A, n)


Measured memory_bytes: 224112
import java.util.Scanner;

	class Main{
		public static void main(String[]args){
            
            
        Scanner sc=new Scanner(System.in);
            int a,b,c;
            a=sc.nextInt();
            b=sc.nextInt();
            c=sc.nextInt();
            
            if(a<b&&b<c)System.out.println("Yes");
            else System.out.println("No");
            
            sc.close();
        }
    }


Measured memory_bytes: 26136
import java.util.Scanner;

public class Main {

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

		final String n = sc.next();

		final String[] nList = n.split("");

		for (int j = 0; j < nList.length; j++) {
			if ((j + 1) % 2 > 0) {
				System.out.print(nList[j]);
			}
		}

	}

}

Measured memory_bytes: 34948
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();

		int c = 0, l = 0;
		for (int i = 0; i < n; i++) {
			switch (s[i]) {
			case '(':
				c++;
				break;
			case ')':
				if (c > 0) c--;
				else l++;
				break;
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < l; i++) sb.append('(');
		sb.append(s);
		for (int i = 0; i < c; i++) sb.append(')');

		out.println(sb.toString());
		out.flush();
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

}

Measured memory_bytes: 21204