akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  int N;
  cin >> N;
  bool departure = true;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin >> vec[i];
  }
  for (int i = 0; i < N; i++)
  {
    if (vec[i] % 2 == 0)
    {
      if (vec[i] % 3 == 0 || vec[i] % 5 == 0)
      {
        continue;
      }
      else
      {
        cout << "DENIED" << endl;
        departure = false;
        break;
      }
    }
  }
  if (departure == true)
  {
    cout << "APPROVED" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << (x) << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }

template<class T> class rollinghash {
public:
	const ull mask30 = (1LL << 30) - 1;
	const ull mask31 = (1LL << 31) - 1;
	const ull mod61 = (1LL << 61) - 1;
	const ull base = 10000001;
	vector<ull> hashvalue, basepower;
	int length;
	ull modulo(ull a) {
		ull au = a >> 61; ull ad = a & mod61;
		ull res = au + ad; if (res >= mod61) res -= mod61;
		return res;
	}
	ull multiply(ull a, ull b) {
		ull au = a >> 31; ull ad = a & mask31;
		ull bu = b >> 31; ull bd = b & mask31;
		ull mid = ad * bu + au * bd;
		ull midu = mid >> 30; ull midd = mid & mask30;
		return au * bu * 2 + midu + (midd << 31) + ad * bd;
	}
	rollinghash(T s) {
		length = s.size();
		hashvalue = vector<ull>(length + 1);
		for (int i = 0; i < length; i++) {
			hashvalue[i + 1] = modulo(multiply(hashvalue[i], base) + s[i] + 1);
		}
		basepower = vector<ull>(length + 1);
		basepower[0] = 1;
		for (int i = 1; i <= length; i++) {
			basepower[i] = modulo(multiply(basepower[i - 1], base));
		}
	}
	ull hash(ll l, ll r) {
		assert(l <= r && 0 <= l && l <= length && 0 < r && r <= length);
		return modulo(hashvalue[r] + mod61 - modulo(multiply(hashvalue[l], basepower[r - l])));
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	sort(all(s), [](string a, string b) { return a.size() < b.size(); });
	unordered_map<ll, int> mp;
	ll ans = 0;
	rep(i, n) {
		int sz = s[i].size();
		rollinghash rol(s[i]);
		int ok = 0;
		rep(j, sz + 1) {
			ans += __builtin_popcount(mp[rol.hash(j, sz)] & ok);
			ok |= 1 << (s[i][j] - 'a');
		}
		mp[rol.hash(1, sz)] |= 1 << (s[i][0] - 'a');
	}
	cout << ans << '\n';
}

Measured memory_bytes: 58612
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

int main(){
    const double BTCJPY = 380000.0;
    int n;
    cin >> n;
    double ans = 0;
    for(int i = 0; i < n; i++){
        double x;
        string str;
        cin >> x >> str;
        if(str == "JPY"){
            ans += x;
        }else{
            ans += x * BTCJPY;
        }
    }
    cout << fixed << setprecision(10) << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
char ch[50];
int main(){
	string s="CODEFESTIVAL2016";
	int n=s.length();
	scanf("%s",ch); int num=0;
	for (int i=0;i<n;i++) if (s[i]!=ch[i]) num++;
	cout<<num<<endl;
}

Measured memory_bytes: 256
using System;
using static System.Console;

class Program {
	static void Main() {
		var X = int.Parse(ReadLine());
		var ans = 1;

		for (var i = 2; i * i <= X; i++) {
			for (var j = i * i; j <= X; j *= i) {
				ans = Math.Max(ans, j);
			}
		}
		WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;            //

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

    ll ans = 1;
    int divisor = 1000000007;
    for (int i = 1; i <= N; i++)
    {
        ans *= i;
        ans %= divisor;
    }
    cout << ans << endl;
    return (0);
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  string s; cin >> s;
  int gx, gy; scanf("%d %d", &gx, &gy);
  int n = s.size();
  vector<int> xmoves, ymoves;
  int x = 0, y = 0;
  int dir = 0;
  for (int i = 0; i < n; ) {
    int j = i;
    while (j < n and s[i] == s[j]) { ++j; }
    if (s[i] == 'F') {
      if (i == 0) { x = (j - i); }
      else if (dir == 0) { xmoves.push_back(j - i); }
      else { ymoves.push_back(j - i); }
    }
    else {
      if ((j - i) % 2) {
        dir = 1 - dir;
      }
    }
    i = j;
  }
  set<int> xcur;
  xcur.insert(x);
  for (int i = 0; i < (int)xmoves.size(); ++i) {
    set<int> next;
    for (set<int>::iterator iter = xcur.begin(); iter != xcur.end(); ++iter) {
      next.insert(*iter - xmoves[i]);
      next.insert(*iter + xmoves[i]);
    }
    xcur = next;
  }
  set<int> ycur;
  ycur.insert(y);
  for (int i = 0; i < (int)ymoves.size(); ++i) {
    set<int> next;
    for (set<int>::iterator iter = ycur.begin(); iter != ycur.end(); ++iter) {
      next.insert(*iter - ymoves[i]);
      next.insert(*iter + ymoves[i]);
    }
    ycur = next;
  }
  printf("%s\n", xcur.count(gx) and ycur.count(gy) ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 768
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	string s;
	cin >> s;

	auto check = [&](int len) {

		if (len == 0) return true;
		unordered_map<string, vector<int>> mmp;
		for (int j = 0; j <= N - len; j++) mmp[s.substr(j, len)].emplace_back(j);
		
		return any_of(mmp.begin(), mmp.end(), [](auto &p) { return p.second.size() >= 2 && (p.second.back() - p.second.front() >= p.first.size());});
	};

	for (int i = 0; i < N; i++) DMP(check(i));

	vector<int> len(N);
	iota(len.begin(), len.end(), 0);
	cout << *partition_point(len.begin(), len.end(), check) - 1 << endl;

	return 0;
}


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

int main() {
    long long a[100][100], b[100][100], c[100][100] = {};
    int n, m, l;
    cin >> n >> m >> l;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++) {
            cin >> b[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int k = 0; k < m; k++) {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            cout << c[i][j];
            if (j < l - 1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3340
#include <bits/stdc++.h>
using namespace std;
long long f(long long x, long long y) {
	long long ret = 0;
	while(y >= 1) ret += y % x, y /= x;
	return ret;
}
long long solve(long long a, long long b) {
	if(a < b) return -1;
	int p = 1;
	while(a / p >= p) p++;
	for(int i = 2; i < p; i++) {
		if(f(i, a) == b) return i;
	}
	for(int i = min({a / p, a - b}); i >= 1; i--) {
		if((a - b) % i == 0) {
			long long r = (a - b) / i + 1;
			if(0 <= b - i && b - i < r) return r;
		}
	}
	if(a == b) return a + 1;
	return -1;
}
long long n, s;
int main() {
	cin >> n >> s;
	cout << solve(n, s) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

void bomb(int field[8][8],int x,int y);

int main(){
	int i,j,k,n;
	int field[8][8];
	char line[9];
	int x,y;
	
	scanf("%d",&n);
	for(i=1;i<=n;i++){		
		for(j=0;j<8;j++){
			scanf("%s",line);
			for(k=0;k<8;k++){
				field[j][k] = line[k] - '0';
			}
		}
		scanf("%d",&x);
		scanf("%d",&y);
		x--; y--;
		
		bomb(field,y,x);
		
		printf("Data %d:\n",i);
		for(j=0;j<8;j++){
			for(k=0;k<8;k++){
				printf("%d",field[j][k]);
			}
			printf("\n");
		}
	}
	
	return 0;
}

void bomb(int field[8][8],int x,int y){
	int i;
	field[x][y] = 0;
	for(i=1;i<=3&&x-i>=0;i++){
		if(field[x-i][y] == 1){
			field[x-i][y] = 0;
			bomb(field,x-i,y);
		}
	}
	for(i=1;i<=3&&x+i<8;i++){
		if(field[x+i][y] == 1){
			field[x+i][y] = 0;
			bomb(field,x+i,y);
		}
	}
	for(i=1;i<=3&&y-i>=0;i++){
		if(field[x][y-i] == 1){
			field[x][y-i] = 0;
			bomb(field,x,y-i);
		}
	}
	for(i=1;i<=3&&y+i<8;i++){
		if(field[x][y+i] == 1){
			field[x][y+i] = 0;
			bomb(field,x,y+i);
		}
	}
}

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

int main(){
  int n;
  cin >> n;
  set<int> a;
  rep(i,n){
    int x;
    cin >> x;
    a.insert(x);
  }
  if(a.size() ==  n) cout  << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 9600
N = int(input())
num = list(map(int,input().split()))
min_num = 10000
right = 0
left = 0
for i in range(N):
	right = sum(num[:i+1])
	left = sum(num[i+1:])
	min_num = min(min_num,abs(right-left))
print(min_num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#define ll long long

using namespace std;

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

    long n, a, b, c;
    cin >> n;

    vector<tuple<int, int, int>> abc;

    vector<tuple<int, int, int>> dp(n, make_tuple(0, 0, 0));

    for (int i = 0; i < n; i++) {
        cin >> a >> b >> c;
        abc.emplace_back(a, b, c);
    }
    dp[0] = abc[0];

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

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


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

#define int long long

signed main(){
  int N;
  vector<vector<int>> A;

  cin>>N;

  A.resize(N, vector<int>(N));

  if(N == 2) {
    cout<<-1<<endl;
    return 0;
  }

  for(int i = 0; i < 3; i++){
    A[i][0] = (i+1)%3;
    A[i][1] = (i+2)%3;
  }

  for(int i = 3; i < N; i++){
    //cout<<"i = "<<i<<endl;
    for(int j = 0; j < i; j++){
      A[j][i-1] = i;
      //cout<<"j = "<<j<<" i = "<<i<<endl;
    }
     for(int j = 0; j <= i; j++){
      A[i][j] = j;
    }
     swap(A[i-1][i-2], A[i-1][i-1]);
  }

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N-1; j++){
      if(j) cout<<" ";
      cout<<A[i][j]+1;
    }
    cout<<endl;
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110

signed main()
{
    string S;
    cin >> S;
    REP(i, S.length()) {
        if(i % 2 == 0) { printf("%c", S[i]); }
    }
    printf("\n");

    return 0;
}


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

using namespace std;


int main() {
	int n, a, b;
	cin >> n >> a >> b;

	if (a > b) {
		cout << "0" << endl;
	} else if (n == 1 && a!=b) {
		cout << "0" << endl;	
	}
	else {
		cout << ((n-1)*1ll*b+a) - ((n-1)*1ll*a+b) + 1<< endl;
	}


}

Measured memory_bytes: 256
def myAnswer(N:int,A:int,B:int) -> int:
   if((N== 1 and  A != B )or B - A < 0): return 0
   ans = (B*(N-1) + A) - (A * (N - 1) + B) + 1
   return ans

def modelAnswer():
   return
def main():
   N,A,B = map(int,input().split())
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
#define mod 1000000007
#define mod2 998244353
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TC int ttttt;cin>>ttttt;while(ttttt--)
#define oo 2000000000000000000
#define mem(a,b) memset(a,b,sizeof(a))

//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;


using namespace std;

bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}

int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

int max(int a,int b){
    return (a>b?a:b);
}

int min(int a,int b){
    return (a<b?a:b);
}

struct node{
    int u,v,w;
    node(int a,int b,int c){
        u = a;
        v = b;
        w = c;
    }
};

struct items{
    int t,d,p,op;
    items(int a,int b,int c,int e){
        t=a;
        d=b;
        p=c;
        op=e;
    }
};

struct compare{
    bool operator() (const items a,const items b) const{
        return a.d < b.d;
    }
    bool operator() (const pair<int,int>a,const pair<int,int>b) const{
        if(a.first == b.first){
            return a.second < b.second;
        }
        return a.first > b.first;
    }
};

int32_t main(){
    IOS  
    int n;
    string s;
    cin >> s;
    n = s.length();
    if(s[0] == '0'){
        cout<<-1<<endl;
        return 0;
    }
    if(s[n-1] == '1'){
        cout<<-1<<endl;
        return 0;
    }
    vector<int>ones;
    for(int i=0;i<n-1;i++){
        if(s[i] != s[n-i-2]){
            cout<<-1<<endl;
            return 0;
        }
        if(s[i] == '1'){
            ones.pb(i);
        }
    }
    vector<pair<int,int>>edges;
    int st = 1;
    int nxt = 2;
    for(int i=0;i<ones.size();i++){
        edges.pb({st,nxt});
        st++;
        nxt++;
    }
    st = 2;
    for(int i=1;i<ones.size();i++){
        int temp = ones[i] - ones[i-1] -1;
        while(temp--){
            edges.pb({st,nxt});
            nxt++;
        }
        st++;
    }
    for(auto x:edges){
        cout<<x.first<<" "<<x.second<<endl;
    }
}   

Measured memory_bytes: 4032
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,i,cnt=0;
  cin >> n;
  long long a[n+1],b[n],c[n+1];
  for(i=0;i<n+1;i++){
    cin >> a[i];
    c[i]=a[i];
  }
  for(i=0;i<n;i++){
    cin >> b[i];
  }
  
  for(i=0;i<n;i++){
    if(a[i]>=b[i]){
      a[i]-=b[i];
      b[i]=0;
    }else{
      b[i]-=a[i];
      a[i]=0;
      a[i+1]=(a[i+1]-b[i]>=0 ? a[i+1]-b[i] : 0);
    }
  }
  
  for(i=0;i<n+1;i++){
    cnt+=(c[i]-a[i]);
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 2560
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


def sum_digit(n):
    return sum(list(map(int, list(str(n)))))


N = int(input())

ans = INF
for i in range(1, N // 2 + 1):
    ans = min(ans, sum_digit(i) + sum_digit(N - i))

print(ans)


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const int IINF = 1e9;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

template <typename T>
void dumpvec(vector<T> vec) {
  for (T cnt : vec) {
    cout << cnt << ", ";
  }
  cout << endl;
}

void chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
  }
}
void chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
  }
}

vector<string> split(string s, string delimiter) {
  int first = 0;
  int last = s.find_first_of(delimiter);
  vector<string> result;

  while (first < s.size()) {
    string sub = s.substr(first, last - first);
    result.push_back(sub);
    first = last + 1;
    last = s.find_first_of(delimiter, first);

    if (last == string::npos) {
      last = s.size();
    }
  }

  return result;
}

string join(vector<string> strings, string delimiter) {
  string result = "";
  for (int i = 0; i < strings.size(); i++) {
    if (result != "") result += delimiter;
    result += strings[i];
  }
  return result;
}

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int freq5 = 0;
  int freq7 = 0;
  if (a == 5) freq5++;
  if (a == 7) freq7++;
  if (b == 5) freq5++;
  if (b == 7) freq7++;
  if (c == 5) freq5++;
  if (c == 7) freq7++;
  cout << ((freq5 == 2 && freq7 == 1) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){

	string s;
	cin >> s;

	int cnt = 0;
	string ans("");
	for(int i=0;i<s.size();i++){
		if( s[i] == 'B' ){
			if( ans.size() != 0 ) ans.pop_back();
		}else{
			ans.push_back(s[i]);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define R_MAX 10
#define C_MAX 10000

int solve(int r, int c, int buf[R_MAX][C_MAX]);

int main(){
    static int buf[R_MAX][C_MAX];
    int r,c;
    int ri,ci;
    int ans;

    while(scanf("%d %d",&r,&c),(r>0)&&(c>0)){
        //入力
        for(ri=0;ri<r;ri++){
            for(ci=0;ci<c;ci++){
                scanf("%d",&(buf[ri][ci]));
            }
        }
        //処理
        ans = solve(r,c,buf);
        //出力
        printf("%d\n",ans);
    }

    return 0;
}


int solve(int r, int c, int buf[R_MAX][C_MAX]){
    int ans;
    int ri,ci,pattern;
    int bits[R_MAX];
    int sum,csum;

    // 行ごとに反転させるかどうかを全パターン試す
    // 2^r(=1<<r)パターンあり、2進数のr桁で 0：反転しない、1：反転する と考える
    ans = 0;
    for(pattern=0;pattern<(1<<r);pattern++){
        for(ri=0;ri<r;ri++){
            bits[ri] = (pattern>>ri) & 0x01;
        }

        // 行の反転有無が決まると、その時の列の状態により
        // 列を反転させるべきかどうかが一意に決まる
        sum = 0;
        for(ci=0;ci<c;ci++){
            csum = 0;
            for(ri=0;ri<r;ri++){
                if(buf[ri][ci]^bits[ri]){
                    csum++;
                }
            }
            if(csum<r-csum){
                csum=r-csum;
            }
            sum += csum;
        }

        if(ans<sum){
            ans = sum;
        }
    }

    return ans;
}




Measured memory_bytes: 2164
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

// long long lcm(long long a, long long b){
//     return a * b / gcd(a, b);
// }

int main(){
    long long n,m,ans;
    cin >> n >> m;
    if(n-2 > 0 && m-2 > 0){
        ans = (n-2)*(m-2);
    }else if(n == 1 && m == 1){
        ans = 1;
    }else if(n == 1 || m == 1){
        ans = -1*(n-2)*(m-2);
    }else{
        ans = 0;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
s = input()
count = int(input())
flg = False
top = ""
for i in range(count):
    tfc = input().split()
    if tfc[0] == "1":
        flg = not flg
    elif tfc[0] == "2":
        if (not flg and tfc[1] == "1") or (flg and tfc[1] == "2"):
            top = top + tfc[2]
        elif (flg and tfc[1] == "1") or (not flg and tfc[1] == "2"):
            s = s + tfc[2]

if flg:
    s = s[::-1] + top
else:
    s = top[::-1] + s 
print(s)

Measured memory_bytes: 4196
let inf = 1_000_000_000_000_000_000L

let n = int64(stdin.ReadLine())
let a = stdin.ReadLine().Split() |> Array.map(int64)

for x in a do
    if x = 0L then
        printfn "0"
        exit(0)

let mutable accum = 1L

for x in a do
    if accum <= inf / x then
        accum <- accum * x
    else
        printfn "-1"
        exit(0)

printfn "%i" accum


Measured memory_bytes: 42504
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
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; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    intl n,k;
    cin >> n >> k;
    bool f[n];
    m0(f);
    rep(i,k){
        intl a;
        cin >> a;
        rep(j,a){
            intl b;
            cin >> b;
            f[b-1] = true;
        }
    }
    intl cnt = 0;
    rep(i,n){
        if(!f[i])cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
input1 = input().split()
a = input1[0]
b = input1[1]
t = input1[2]
a = float(a)
b = float(b)
t = float(t)
total = 0 #ビスケットの総数
T = t + 0.5 #0.5足した後のタイム

T -= a
while T > 0:
    total += b
    T -= a

total = int(total)

print(total)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#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 REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};

int main(){
	int n,h;
	cin>>n;
	h=n/2;
	int a[200001],b[200001];
	REP(i,n){
		int value;
		cin>>value;
		a[i]=value;
		b[i]=value;
	}
	SORT(b,n);
	int med=b[h-1];
	REP(i,n){
		if(a[i]<=med){
			cout<<b[h]<<endl;
		}
		else{
			cout<<b[h-1]<<endl;
		}
	}
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n;
long long seg[4 * N], h[N], a[N];
void upd(int idx, int start, int end, int id, long long val)
{
	if (start > end || start > id || end < id)
		return;
	if (start == end)
		seg[idx] = val;
	else
	{	
		int mid = (start + end) / 2;
		upd(2 * idx + 1, start, mid, id, val);
		upd(2 * idx + 2, mid + 1, end, id, val);
		seg[idx] = max(seg[2 * idx + 1], seg[2 * idx + 2]);
	}
}
long long query(int idx, int start, int end, int l, int r)
{
	if (start > end || start > r || end < l)
		return 0;
	else if (start >= l &&  end <= r)
		return seg[idx];
	else
	{
		int mid = (start + end) / 2;
		long long lmax = query(2 * idx + 1, start, mid, l, r);
		long long rmax = query(2 * idx + 2, mid + 1, end, l, r);
		return max(lmax, rmax);
	}
}
int main(int argc, char const *argv[])
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> h[i];
		h[i] --;
	}
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		long long mx = query(0, 0, n - 1, 0, h[i]);
		upd(0, 0, n - 1, h[i], mx + a[i]);
	}
	cout << query(0, 0, n - 1, 0, n - 1);
	return 0;
}

Measured memory_bytes: 8448
#![allow(non_snake_case)]

use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let A: i32 = read();
    let B: i32 = read();
    let C: i32 = read();
    let l: Vec<i32> = (0..n).map(|_| read()).collect();

    println!("{}", dfs(&l, n, 0, 0, 0, 0, A, B, C));
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

const INF: i32 = 1_000_000_000;

fn dfs(l: &[i32], n: usize, cur: usize, a: i32, b: i32, c: i32, A: i32, B: i32, C: i32) -> i32 {
    if cur == n {
        if *[a, b, c].iter().min().unwrap() > 0 {
            (a - A).abs() + (b - B).abs() + (c - C).abs() - 30
        } else {
            INF
        }
    } else {
        let ret0 = dfs(l, n, cur + 1, a, b, c, A, B, C);
        let ret1 = dfs(l, n, cur + 1, a + l[cur], b, c, A, B, C) + 10;
        let ret2 = dfs(l, n, cur + 1, a, b + l[cur], c, A, B, C) + 10;
        let ret3 = dfs(l, n, cur + 1, a, b, c + l[cur], A, B, C) + 10;
        *[ret0, ret1, ret2, ret3].iter().min().unwrap()
    }
}


Measured memory_bytes: 4352
<?php

$score  = array(0, 0);

fscanf(STDIN, '%d', $n);
 
for ($i = 0; $i < $n; $i++) {
    $card = explode(' ', trim(fgets(STDIN)));

    foreach (getPoint($card) as $player => $point) {
        $score[$player] += $point;
    }
}

echo implode(' ', $score), PHP_EOL;


function getPoint($card)
{
    if (count(array_unique($card)) == 1) {
        return array(1, 1);
    }

    return array(array_search(max($card), $card) => 3);
}

Measured memory_bytes: 6636
N, K = map(int, input().split())
gcd_list = [0] * K#K, K-1, K-2の順
MOD = 10 ** 9 + 7

for i in range(K, 0, -1):
  #print(i)
  ans2 = pow((K // i), N, MOD)#
  x = i
  while x <= K:
    ans2 -= gcd_list[K - x]
    x += i
  gcd_list[K - i] = ans2 % MOD
  
ans = 0  
for i in range(K):
  ans += (gcd_list[i] * (K - i)) % MOD
  
print(ans % MOD)

Measured memory_bytes: 11236
import heapq

def main():
    n = int(input())
    arr = list(map(int,input().split()))
    nums = {}
    for i in range(1,n+1):
        nums[i] = []

    dp = [0]*n
    heap = []
    for i in range(n):
        nums[arr[i]].append(i)
        if arr[i] == 1:
            dp[i] = 1
            heapq.heappush(heap,(arr[i],i))

    if not heap:
        print(-1)
        return
    visited = set()
    while heap:
        curr = heapq.heappop(heap)
        if curr not in visited:
            visited.add(curr)
            index = curr[1]
            num = curr[0]
            #print(curr,num)
            if num+1 in nums.keys():
                for kid in nums[num+1]:
                    if kid > index:
                        #print(num,kid,dp[kid])
                        dp[kid] = max(dp[kid],dp[index]+1)
                        heapq.heappush(heap,(num+1,kid))

    #print(dp)
    print(n-max(dp))
    
    

main()


Measured memory_bytes: 100020
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>

using namespace std;

struct Edge{int src, dst;};

const int MAX = 5010;
bool exist = false;

vector<int> topological_sort(int n, const vector<Edge>& graph){
  int inEdge[MAX];
  bool come[MAX];
  vector<int> node(n);
  vector<int> order;
  queue<int> Q;

  memset(inEdge,0,sizeof(inEdge));
  memset(come,false,sizeof(come));
 
  for(int i = 0; i < n; i++) node[i] = i+1;

  for(int i = 0; i < (int)graph.size(); i++) inEdge[graph[i].dst]++;
  for(int i = 0; i < (int)node.size(); i++) if(inEdge[node[i]]==0) Q.push(node[i]);
 
  while(!Q.empty()){
    if(Q.size() >= 2) exist = true;

    const int now = Q.front();
    Q.pop();

    if(come[now]) continue;
    come[now] = true;

    order.push_back(now);
    for(int i = 0; i < (int)graph.size(); i++) if(graph[i].src==now) inEdge[graph[i].dst]--;
    for(int i = 0; i < (int)node.size(); i++) if(inEdge[node[i]]==0 && !come[node[i]]) Q.push(node[i]);
  }
  return order;
}

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
 vector<Edge> G(m);
  for(int i = 0; i < m; i++) cin >> G[i].src >> G[i].dst;
  vector<int> ans = topological_sort(n,G);
  for(int i = 0; i < (int)ans.size(); i++) cout << ans[i] << endl;
  cout << (exist?1:0) << endl;
  return 0;
}

Measured memory_bytes: 2128
#include<stdio.h>
  
int main() {
     
  int H,W,i,j;
  
   while (1) {
      scanf("%d%d",&H,&W);
      if  (H == 0 && W == 0) {
         break;
      }
      for (j=0; j<H; j++) {      
         for (i=0; i<W; i++) {
            if ( (i+j)%2==0 ) {
               printf("#");
            } else {
               printf(".");
            }
         }
      printf("\n");
      }
   printf("\n");
   }
     
   return 0;
        
}

Measured memory_bytes: 572
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
  int a,b,c,d,e;
   char g[20]; string h,i;
    cin >> a;
 	if(a==3||a==5||a==7){
      cout <<"YES";
    }else cout <<"NO";
}

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

ll L[100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	L[0] = 2;
	L[1] = 1;
	for(int i = 2; i < 90; i++){
		L[i] = L[i - 1] + L[i - 2];
	}
	int N;
	cin >> N;
	cout << L[N] << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        List<int> abcd = Console.ReadLine().ToCharArray().Select((c) => int.Parse(c.ToString())).ToList();

        for(byte i = 0; i < 8; i++) //000~111
        {
            bool[] pm =
            {
                ((i & 1) == 1),
                ((i & 2) == 2),
                ((i & 4) == 4),
            };
            int culc = abcd[0] + (pm[0] ? 1 : -1) * abcd[1] + (pm[1] ? 1 : -1) * abcd[2] + (pm[2] ? 1 : -1) * abcd[3];
            if(culc == 7)
            {
                string ans = "";
                for(int j = 0; j < 4; j++)
                {
                    ans += abcd[j];
                    if (j < 3) ans += (pm[j]) ? "+" : "-";
                }
                ans += "=7";
                Console.WriteLine(ans);
                return;
            }
        }
    }
}

Measured memory_bytes: 13268
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s; cin >> s;
  bool flag = true;
  REP(i,s.size()){
    if(i%2==0 && s[i]=='L') flag = false;
    if(i%2==1 && s[i]=='R') flag = false;
  }
  cout << (flag ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int dp[(1<<20)];

void chmax(int &a,int b){
  if(a<b) a=b;
}

int main(){
  int N;
  ll K;
  cin>>N>>K;
  vector<ll> A(N);
  rep(i,N) cin>>A[i];

  for(int i=1;i<(1<<N);i++){
    ll res=0;
    for(int j=0;j<N;j++){
      if(i&(1<<j)){
        chmax(dp[i],dp[i^(1<<j)]);
        res+=A[j];
      }
    }

    if(res==K) dp[i]=1;
  }

  int ans=N;
  for(int i=1;i<(1<<N);i++){
    if(dp[i]) continue;
    int num=0;
    for(int j=0;j<N;j++){
      if(i&(1<<j)) num++;
    }
    ans=min(ans,N-num);
  }

  cout<<ans<<endl;

  return 0;
}



Measured memory_bytes: 7196
package main

import (
	"fmt"
	"math"
)

func main() {
	var k, x int
	fmt.Scan(&k, &x)

	min := math.Max(float64(x-k+1), -1000000)
	max := math.Min(float64(x+k-1), 1000000)

	for i := min; i <= max; i++ {
		if i == max {
			fmt.Println(i)
			break
		}
		fmt.Print(i, " ")
	}
}


Measured memory_bytes: 512
Var A,B,N:Longint;
    D:Array[1..100000] Of Qword;

Procedure Xuli;
Var i:Longint;
Begin
        D[1]:=1;
        For i:=2 to 100000 Do D[i]:=((D[i-1] Mod 1000000007)*(i Mod 1000000007))Mod 1000000007;
End;

Begin
        //Assign(Input,'TRAINED.INP'); Reset(Input);
        ///Assign(Output,'TRAINED.OUT'); Rewrite(Output);
        Readln(A,B);
        Xuli;
        If ABS(A-B)>1 Then
                Begin
                Write(0);
                Halt;
                End;
        N:=(D[B]*D[A])Mod 1000000007;
        If A=B Then
                Begin
                N:=(D[B]*D[A]*2)Mod 1000000007;
                Write(N);
                Halt;
                End;
        Write(N);
        //Close(Input);
        //Close(Output);
End.


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,n,m,k,food[35]={};
  cin>>n>>m;
  rep(i,n){
      cin>>k;
      rep(j,k){
	  cin>>a;
	  food[a]++;
      }
  }
  int sum=0;
  reps(i,m){
      if(food[i]==n){
	  sum++;
      }
  }
  cout<<sum<<'\n';
  
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

      int n = Integer.parseInt(sc.next());
      int k = Integer.parseInt(sc.next());

      String s = sc.next();
      int lng = s.length();
      char[] c = new char[lng];
      for(int i=0;i<lng;i++){
        c[i] = s.charAt(i);
      }

      int[] kore = new int[n];
      int[] or01 = new int[n];
      int cnt = 0;
      for(int i=0;i<n-1;i++){
        if(c[i]==c[i+1]){
          kore[cnt]++;
        }
        else{
          if(c[i]=='0'){
            or01[cnt] = 0;
          }
          else{
            or01[cnt] = 1;
          }
          cnt++;
        }
      }
      for(int i=0;i<=cnt;i++){
        kore[i]++;
      }

//////main////////////////////////////////////
int range = 2*k+1;
int ans = 0;
int max = 0;
for(int i=-range+1;i<=lng-range;i++){

if(i<0){
//////////////////////////////////
for(int j=0;j<range+i;j++){
  max += kore[j];
}
//////////////////////////////////
}
else if(0<=i && i<=lng-range){
//////////////////////////////////
  if(or01[i]==1){
    for(int j=i;j<i+range;j++){
      max += kore[j];
    }
  }
//////////////////////////////////
}
else if(lng-range<i){
//////////////////////////////////
for(int j=i;j<lng;j++){
  max += kore[j];
}
//////////////////////////////////
}
  ans = Math.max(ans,max);
  max = 0;
}

System.out.println(ans);
//////////////////////////////////////////////

      /*for(int kores : kore){
        System.out.println(kores);
      }*/

    }
}


Measured memory_bytes: 28820
#include <iostream>

using namespace std;

long gcd(long a,long b){
	long tmp;
	while(a%b!=0){
		tmp = b;
		b = a%b;
		a = tmp;
	}
	return b;
}

int main(){
	long long a,b;
	cin >> a >> b;
	cout << a * b / gcd(a,b) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#define ll long long
int pos(int n)
{
    if(n<0)
        return 0;
    else
        return n;
}
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n],b[n];
    int cnt=0;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    if(a[0]>1)
    {
        cout<<-1<<endl;
    }
    else
    {
        int nn=n;;
        for(int i=0; i<nn; i++)
        {
            for(int j=n-1; j>=0; j--)
            {
                if(a[j]==j+1)
                {
                    b[cnt++]=a[j];
                    for(int k=j; k<n-1; k++)
                    {
                        a[k]=a[k+1];
                    }
                    n--;
                    break;
                }
            }
        }
        if(cnt!=nn)
        {
            cout<<-1<<endl;
        }
        else
        {
            for(int i=cnt-1; i>=0; i--)
            {
                cout<<b[i]<<endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#[doc = " https://github.com/hatoo/competitive-rust-snippets"]
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (a, b) = get!(usize, usize);

    println!("{}", [2 * a - 1, 2 * b - 1, a + b].iter().max().unwrap());
}


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

int main() {
	int N;
	string S;
	cin >> N>>S;
	
	int count=1;
	char fir;
	char sec;
	fir =S.at(0);
	
	for(int i=1;i<N;i++){
		sec= S.at(i);
		if(fir!=sec){
			count ++;
		}
		fir=sec;
	}
	
	cout << count << endl;
}



Measured memory_bytes: 512
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int x, y, z;
    scan(x, y, z);
    swap(x, y);
    swap(x, z);
    writefln("%s %s %s", x, y, z);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 256
from collections import Counter
n=int(input())
alpha = 'abcdefghijklmnopqrstuvwxyz'
ans=Counter(input())
for _ in range(n-1):
    temp=Counter(input())
    for char in alpha:
        ans[char]=min(ans[char],temp[char])
for char in alpha:
    for _ in range(ans[char]):
        print(char,end='')

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxm=2e3+5;
const int mod=1e9+7;
int d[maxm][maxm];
int a[maxm];
int b[maxm];
int n,m;
signed main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)cin>>b[i];
    //初始化一边为0的情况,因为下面dp的时候不枚举0
    for(int i=0;i<=n;i++)d[i][0]=1;
    for(int i=0;i<=m;i++)d[0][i]=1;
    //dp
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            d[i][j]=(d[i-1][j]+d[i][j-1]-d[i-1][j-1])%mod;
            if(a[i]==b[j])d[i][j]=(d[i][j]+d[i-1][j-1])%mod;
        }
    }
    cout<<(d[n][m]+mod)%mod<<endl;
    return 0;
}
/*
令d[i][j]表示序列a前i个数,序列b前j个数匹配的子序列数,
转移:
d[i][j]=d[i-1][j]+d[i][j-1]-d[i-1][j-1]
计算d[i][j]的时候,d[i-1][j]和d[i][j-1]一定已经计算出来了,
方案数为d[i-1][j]加上d[i][j-1],因为d[i-1][j-1]重复计算了,要容斥掉.

如果a[i]==b[j],那么d[i][j]+=d[i-1][j-1]
因为可以将a[i]和b[j]加入d[i-1][j-1]的每个匹配的末尾,方案数为d[i-1][j-1]

*/


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int V;
vector<int> G[1001];
int match[1001];
bool used[1001];

bool dfs(int v) {
    used[v] = true;
    for (int i = 0; i < (int)G[v].size(); i++) {
        int u = G[v][i], w = match[u];
        if (w < 0 or not used[w] and dfs(w)) {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching() {
    int ret = 0;
    memset(match, -1, sizeof(match));
    for (int i = 0; i < V; i++) {
        if (match[i] < 0) {
            for (int j = 0; j < V; j++) {
                used[j] = false;
            }
            if (dfs(i)) {
                ret++;
            }
        }
    }
    return ret;
}

int gcd(int x, int y) {
    int n = max(x, y);
    int m = min(x, y);
    return m == 0 ? n : gcd(m, n % m);
}

int main() {
    vector<int> res;
    while (true) {
        int m, n;
        cin >> m >> n;
        V = m + n;
        if (m == 0) break;
        vector<int> b(m), r(n);
        for (int i = 0; i < m; i++) {
            cin >> b[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> r[i];
        }
        vector<int> new_G[1001];
        for (int i = 0; i <= 1000; i++) {
            G[i] = new_G[i];
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (gcd(b[i], r[j]) >= 2) {
                    G[i].push_back(m + j);
                    G[m + j].push_back(i);
                }
            }
        }
        res.push_back(bipartite_matching());
    }
    for (int i = 0; i < (int)res.size(); i++) {
        dump(res[i]);
    }
    return 0;
}



Measured memory_bytes: 4868
import sys
N = int(input())
task = list()
for _ in range(N):
  task.append(list(map(int,input().split())))
task.sort(key=lambda x:x[1])
time = 0
for i in range(N):
  time += task[i][0]
  if time > task[i][1]:
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 53728
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <stack>
#include <string.h>
#include <unordered_map>
using namespace std;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define left  (2*idx)+1
#define right (2*idx)+2
#define pb push_back
#define ll long long
#define all(x) x.begin(),x.end()


int main()
{
	FIO;
	string s;
	cin >> s;

	int n = s.length();
	for(int i=0; i<n; i++)
	{
		if(i%2 == 0 && s[i] == 'L')
		{
			cout << "No\n";
			return 0;
		}
		if(i%2 == 1 && s[i] == 'R')
		{
			cout << "No\n";
			return 0;
		}
	}

	cout << "Yes\n";
	return 0;
	
}

Measured memory_bytes: 256
let cache = new System.Collections.Generic.Dictionary<_,_>()
let mutable count = 0L
let sum s =
    match cache.TryGetValue s with
    | true, v -> cache.Remove(s) |> ignore; cache.Add(s, v + 1L); count <- count + v
    | false, _ -> cache.Add(s, 1L)

let n = stdin.ReadLine() |> int
for i in 1..n do stdin.ReadLine() |> Seq.sort |> Seq.map string |> String.concat "" |> sum
printfn "%d" count


Measured memory_bytes: 33988