akhauriyash/Code-Regression huggingface dataset:
import Data.Function(on)
import Text.Printf(printf)

main :: IO ()
main = do
    input <- getLine
    let [a, b] = map read . words $ input
        d = a `div` b :: Int
        r = a `mod` b :: Int
        f = ((/) `on` fromIntegral) a b :: Double
    printf "%d %d %.8f\n" d r f

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

#define ll long long
#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back
#define debug(x) cout << x << endl;
#define END cout << endl;
#define sorti(x) sort(x.begin(), x.end())

int d[401][401];
ll ans = 0;
long long h,w;
// count
ll cs = 0, cp = 0;
char s[401][401];

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
map<pair<int,int>, bool> mp;

void dfs(int x, int y, char now) {
  if (now == '#') {
    cs++;
    pair<int,int> p = make_pair(x,y);
    mp[p] = true;
  }
  else cp++;
  d[x][y] = 1;

  for (int i = 0; i < 4; ++i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (nx >= 0 and nx < h and ny >= 0 and ny < w and s[nx][ny] != now and d[nx][ny] == 0) {
      dfs(nx,ny,s[nx][ny]);
    }
  }
}

int main() {
  cin >> h >> w;

  vector<pair<int,int> > p;
  rep(i,h) rep(j,w){
    cin >> s[i][j];
  }

  pair<int,int> pp;
  for (int tt = 0; tt < h; ++tt) {
    for (int i = 0; i < w; ++i) {
      // kuromasukara
      pp = make_pair(tt,i);
      if (s[tt][i] == '#' and !mp[pp]) {
        dfs(tt,i,'#');
        ans += cs * cp;
        cs = 0, cp = 0;
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 8;

int a[MAXN];

int main()
{
    #ifdef LOCAL
    freopen("a.txt", "r", stdin);
    //freopen("a.out", "w", stdout);
    int T = 5;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    int n, i, cnt4 = 0, cnt2 = 0;
    bool ans = false;
    cin >> n;
    for(i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] % 4 == 0){
            cnt4++;
        }
        else if(a[i] % 2 == 0){
            cnt2++;
        }
    }
    if(cnt4*2 + 1 >= n){
        ans = true;
    }
    if(cnt4 * 2 >= n - cnt2){
        ans = true;
    }
    if(ans)  cout << "Yes" <<endl;
    else cout << "No" << endl;

    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



Measured memory_bytes: 640
my ($n, $k) = split(/\s+/, <>);
my $ans = 0;
for my $i (1..$n) {
    my $a = $i;
    my $p = 1;
    for (my $j=1; $a<$k; $j++) {
	$a *= 2;
	$p /= 2;
    }
    $ans += $p;
}
printf "%16.15f\n", $ans/$n;


Measured memory_bytes: 512
def count_five(n):
  ret = 0
  while n and not n % 5:
    ret += 1
    n //= 5
  return ret

while True:
  n = int(input())
  if not n:
    break

  ans = 0
  for i in range(n + 1):
    ans += count_five(i)
  print(ans)



Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
int main( ){
	string x;
	cin>>x;
	if(x=="Sunny")
	cout<<"Cloudy";
	if(x=="Cloudy")
	cout<<"Rainy";
	if(x=="Rainy")
	cout<<"Sunny";
	return 0;
}

Measured memory_bytes: 256
//In the name of God

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 2e5+10 , mod = 1e9+7;

vector <pii> v;
int dp[N] , fac[N] , rev[N];

inline int power(int x , int y){
   int ret = 1;
   for( ; y ; y /= 2){
      if(y & 1)
         ret = 1ll * ret * x % mod;
      x = 1ll * x * x % mod;
   }
   return ret;
}

int comb(int x , int y){
   return 1ll * fac[y] * rev[x] % mod * rev[y - x] % mod;
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   fac[0] = rev[0] = 1;
   for(int i = 1 ; i < N ; i++){
      fac[i] = 1ll * fac[i - 1] * i % mod;
      rev[i] = power(fac[i] , mod - 2);
   }
   int n , m , k;
   cin >> n >> m >> k;
   for(int i = 0 ; i < k ; i++){
      int r , c;
      cin >> r >> c;
      v.push_back({r , c});
   }
   v.push_back({n , m});
   sort(v.begin() , v.end());
   for(int i = 0 ; i <= k ; i++){
      int r = v[i].first , c = v[i].second;
      dp[i] = comb(r - 1 , r - 1 + c - 1);
      for(int j = 0 ; j < i ; j++){
         int r2 = v[j].first , c2 = v[j].second;
         if(c2 > c)
            continue;
         dp[i] -= 1ll * dp[j] * comb(c - c2 , c - c2 + r - r2) % mod;
         dp[i] += mod;
         dp[i] %= mod;
      }
   }
   cout << dp[k];
   return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  int d = 0;
  ll ans = infll;
  rep(cnt,2) {
    int tot = 0;
    ll tmp = 0;
    rep(i,n) {
      tot += a[i];
      if(i%2 == d && tot <= 0) {
        tmp += abs(1-tot);
        tot = 1;
      }
      if(i%2 != d && tot >= 0) {
        tmp += abs(-1-tot);
        tot = -1;
      }
    }
    d = 1;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int ans = 0;
    int n;
    string a, b, c;

    cin >> n;
    cin >> a >> b >> c;

    for (int i = 0; i < n; i++) {
        if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i]) {
            ans = ans + 2;
        } else if (!(a[i] == b[i] && b[i] == c[i])) {
            ans = ans + 1;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
ostream &operator<<(ostream &os, const vector<int> &a) {
	os<<"[";
	rep(i,a.size()){
		os<<a[i];
		if(i<a.size()-1) os<<",";
	}
	os<<"]";
	return os; 
}
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int V[58];
int main()
{
	int out=0,n,K;
	cin>>n>>K;rep(i,n) cin>>V[i];
	rep(i,n+1) REP(j,i,n+1){
		vector<int> v;
		int sum=0,rest=K-i-(n-j);
		if(rest<0) continue;
		rep(k,i) v.pb(V[k]),sum+=V[k];
		REP(k,j,n) v.pb(V[k]),sum+=V[k];
		if(v.size()<1) continue;
		sort(All(v));
		//cout<<i<<' '<<j<<' '<<sum<<' '<<v<<endl;
		rep(k,min(rest,(int)v.size())){
			if(v[k]<0) sum-=v[k];
		}
		out=max(out,sum);
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ll H,N;
  cin >> H >> N;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    H -= a;
  }
  if(H <= 0){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# set
n,k = gets.chomp.split(" ").map(&:to_i)
enemy_arr = gets.chomp.split(" ").map(&:to_i)
enemy_arr.sort!.reverse!
enemy_arr_length = enemy_arr.length
count = 0

# main
if enemy_arr.length > k then
  enemy_arr.shift(k)
  (n - k).times do
    count += enemy_arr.shift()
  end
end

print ("#{count}\n") 

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

using namespace std;

int main() {
    string n;
    cin >> n;

    int sum = 0;
    for (auto s:n) {
        sum += s - '0';
    }

    auto tmp = (int) ((n[0] - '1') + 9 * (n.size() - 1));
    cout << max(tmp, sum) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
int D,G,P[11],C[11];

int main(){
	cin >> D >> G;
	vector<pair<int,int>> v;
	for(int i=0;i<D;i++){
		cin >> P[i] >> C[i];
	}	
	int ans = 1e9;
	for(int i=0;i<(1<<D);i++){
		int preans = 0,id = -1,score = 0;
		for(int j=0;j<D;j++){
			if(i & (1<<j)){
				preans += P[j];
				score += C[j]+P[j]*100*(j+1);
			}else{
				id = j;
			}
		}
		if(id>=0){
			int count = 0;
			while(count<P[id]-1 && score<G){
				score += 100*(id+1);
				count++;
				preans++;
			}
		}
		if(score>=G) ans = min(preans,ans);
	//	cout << id << " " << score << endl;
	}
	cout << ans << endl;
}

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



   int main(){
      int n,t;
      string s;
      int ans = 0;
      cin >> n >> t;
      int now;
      cin >> now;
      now+=t;
      ans+=t;
      rep(i,n-1){
         int tmp;
         cin >> tmp;
         if (tmp < now){
            ans+=(t-(now-tmp));
            now = tmp+t;
            //cout << now-tmp << endl;
         }
         else {
            ans += t;
            now = tmp+t;
            //cout << now << endl;
         }
      }
      cout << ans << endl;
      
      return 0;
      
   }



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main()
{
  unsigned N;
  std::cin >> N;
  
  std::vector<unsigned> a(N);
  N_TIMES(n, N) {
    std::cin >> a[n];
  }
  
  std::vector<unsigned> c(1e+5 + 1, 0);
  N_TIMES(n, N) {
    ++c[a[n] + 0];
    ++c[a[n] + 1];
    ++c[a[n] + 2];
  }
  
  auto itr = std::max_element(c.begin(), c.end());
  std::cout << (*itr) << std::endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int solve(string s){
    int res = 0;
    for(int i = 0; i<s.size()-2; i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2] == 'C'){
            res++;
        }
    }
    return res;
}
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    cout<<solve(s)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int n = sc.nextInt();
		int sum = 0;

		for(int i = 0; i < n ; i++) {
			sum += sc.nextInt();
		}

		if(sum >= h) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


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

class dice
{
  int top,front,back,rightside,leftside,below;
public:
  void north(),south(),east(),west();
  void input(){ cin >> top >> front >> rightside
                    >> leftside >> back >> below;};
  void output(){cout << top << endl;};
};

void dice::north()
{
  int t=top;
  top=front;
  front=below;
  below=back;
  back=t;
}
void dice::south()
{
  int t=top;
  top=back;
  back=below;
  below=front;
  front=t;
}
void dice::east()
{
  int t=top;
  top=leftside;
  leftside=below;
  below=rightside;
  rightside=t;
}
void dice::west()
{
  int t=top;
  top=rightside;
  rightside=below;
  below=leftside;
  leftside=t;
}

int main()
{
  dice dice01;
  dice01.input();
  char ward;
  while(cin >> ward)
    {
      if(ward=='N') dice01.north();
      else if(ward=='S') dice01.south();
      else if(ward=='E') dice01.east();
      else if(ward=='W') dice01.west();
    }
  dice01.output();
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	int answer = 0;
	for (int C = 1; C <= N; C += 2) {
		int num_of_divisors = 0;
		for (int X = 1; X <= C; ++X) {
			if (C % X == 0) {
				++num_of_divisors;
			}
		}
		if (num_of_divisors == 8) {
			++answer;
		}
	}
	cout << answer << '\n';
	return 0;
}


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

//#define lp_i(k,n)  for(int i = (k); i < (n); i++)
//#define lp_j(k,n)  for(int j = (k); j < (n); j++)
//#define lp_ui(k,n) for(uint32_t i = (k); i < (n); i++)
//#define lp_uj(k,n) for(uint32_t j = (k); j < (n); j++)
//
//typedef uintmax_t    ull;
//typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
//typedef uint8_t      uc;

using namespace std;

int main(void)
{
	ui N{ 0 };
	cin >> N;

	vector<ul> arrayA(N);
	ul sum{ 0 };
	ul halfSum{ 0 };

	for (ui i = 0; i < N; ++i)
	{
		cin >> arrayA[i];

		sum += arrayA[i];
		if (i % 2 == 0)
		{
			halfSum += arrayA[i];
		}
	}

	// X_0の導出
	ul ans = halfSum * 2 - sum;
	cout << ans << " ";

	for (ui i = 0; i < N - 1; ++i)
	{
		// X_i = A_i * 2 - X_(i-1)
		ans = arrayA[i] * 2 - ans;
		cout << ans << " ";

		//if (i != N - 2)
		//{
		//	cout << " ";
		//}
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<string>

using namespace std;

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

	if (a + b >= 10)cout << "error" << endl;
	else cout << a + b << endl;
        return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#define MEM(x,y) memset ( x , y , sizeof ( x ) )
#define rep(i,a,b) for (int i = (a) ; i <= (b) ; ++ i)
#define per(i,a,b) for (int i = (a) ; i >= (b) ; -- i)
#define pii pair < int , int >
#define one first
#define two second
#define rint read<int>
#define int long long
#define pb push_back
#define db double
#define ull unsigned long long
#define lowbit(x) ( x & ( - x ) )
#define mp std::make_pair

using std::queue ;
using std::set ;
using std::pair ;
using std::max ;
using std::min ;
using std::priority_queue ;
using std::vector ;
using std::swap ;
using std::sort ;
using std::unique ;
using std::greater ;

template < class T >
    inline T read () {
        T x = 0 , f = 1 ; char ch = getchar () ;
        while ( ch < '0' || ch > '9' ) {
            if ( ch == '-' ) f = - 1 ;
            ch = getchar () ;
        }
       while ( ch >= '0' && ch <= '9' ) {
            x = ( x << 3 ) + ( x << 1 ) + ( ch - 48 ) ;
            ch = getchar () ;
       }
       return f * x ;
    }

int x , y ;

signed main () {
	x = rint () ; y = rint () ;
	for (int i = 0 ; i <= x ; ++ i)
			if ( i * 2 + 4 * ( x - i ) == y ) {
				puts ("Yes") ;
				return 0 ;
			}
	puts ("No") ;
    return 0 ;
}


Measured memory_bytes: 3624
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ans = 0
drink_num = 0
# 値段に関してソート
ab.sort(key=lambda shop: shop[0])
for i in range(n):
    if (drink_num + ab[i][1]) > m:
        ans += ab[i][0] * (m - drink_num)
        drink_num += m - drink_num
        break
    ans += ab[i][0] * ab[i][1]
    drink_num += ab[i][1]
print(ans)

Measured memory_bytes: 29028
import math

def solve(a,c,d):
    x=a+1
    x-=a//c+1
    x-=a//d+1
    x+=a//(c*d//math.gcd(c,d))+1
    return x

A,B,C,D=map(int,input().split())
print(solve(B,C,D)-solve(A-1,C,D))


Measured memory_bytes: 9156
#include <cstdio>
#include <algorithm>

using namespace std ;
int n; 
int d[1000] ;
int sum ;

int main(void){
	scanf("%d",&n) ;
	for(int i=0; i<n; i++) scanf("%d",&d[i]) ;
	sort(d,d+n) ;
	for(int i=0; i<n; i++) sum += d[i] ;
	int i = 0 ;
		
	while(sum%10==0 && i<n) {
		if(d[i]%10!=0) sum-=d[i] ;
		i++ ;
	}
	if(sum%10==0) sum = 0 ;
	printf("%d\n",sum) ;
	return 0 ;
}

Measured memory_bytes: 128
from functools import reduce
def solve():
    N = int(input())
    A = list(map(int,input().split()))

    diffs_perm = []
    dfs(list(),N,diffs_perm)

    cnt = 0
    for p in diffs_perm:
        B = A[:]
        for i in range(N):
            B[i] += p[i]
        
        if reduce(lambda a,b:a*b, B) % 2 == 0:
            cnt += 1
    
    print(cnt)

def dfs(diffs,N,res):
    if len(diffs) == N:
        res.append(diffs)
        return
    dfs(diffs[:]+[1],N,res)
    dfs(diffs[:]+[0],N,res)
    dfs(diffs[:]+[-1],N,res)


if __name__ == '__main__':
    solve()

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s(n + 1);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.at(i + 1) = (s.at(i) + a - 1) % k;
  }
  map<int, int> m;
  int64_t ans = 0;
  for (int i = 0; i <= n; i++) {
    if (i >= k) m[s[i - k]]--;
    ans += m[s[i]];
    m[s[i]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
bool dp[82][82][82*82*2];
int differ[82][82],A[82][82],B[82][82];
int main()
{
	int H,W;
	cin>>H>>W;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>A[i][j];
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			cin>>B[i][j],
			differ[i][j]=abs(A[i][j]-B[i][j]);
	dp[0][0][differ[0][0]]=true;
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			for(int k=0;k<=(i+j+1)*80;k++)
				if(dp[i][j][k])
				{
					if(i!=H-1)
					{
						dp[i+1][j][k+differ[i+1][j]]=dp[i+1][j][abs(k-differ[i+1][j])]=true;
					}
					if(j!=W-1)
					{
						dp[i][j+1][k+differ[i][j+1]]=dp[i][j+1][abs(k-differ[i][j+1])]=true;
					}
				}
	for(int i=0;i<82*82*2;i++)
		if(dp[H-1][W-1][i])
		{
			cout<<i<<endl;
			return 0;
		}
	return 0;
}

Measured memory_bytes: 87424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  string s; cin>>s;
  int K; cin>>K;
  int N = s.size();
  string d[N*N];
  ll p = 0;
  REP(i,N){
    for(int j=1;j<=min(K,N-i);j++){
      d[p] = s.substr(i,j);
      ++p;
    }
  }
  sort(d,d+p);
  if(K==1){cout<<d[0];}
  else{
    ll n=1;
    string pre = d[0];
    for(int i=1;i<p;i++){
      if(pre==d[i]){
        continue;
      }else{
        pre = d[i];
        n++;
        //cout << n<<" " <<pre<<"\n";
        if(n==K){cout << pre; break;}
      }
    }
  }
}


Measured memory_bytes: 196736
import java.util.*;

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

        LinkedList<Integer> a = new LinkedList<>();
        S.chars().forEach(c -> {
            a.add(c);
        });

        do{
            a.pollLast();
        } while (false == isEvenString(a));

        System.out.print(a.size());
    }

    private static boolean isEvenString(List s){

        if(s.size() % 2 != 0){
            return false;
        }

        List head = s.subList(0, s.size() / 2);
        List tail = s.subList(s.size() / 2, s.size());
        return head.equals(tail);

    }
}

Measured memory_bytes: 26828
#include<cstdio>
#define mod 1000000007
#define N 100020
int fac[N],a[N],inv[N],ivs[N];
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	fac[0]=1;for (int i=1;i<=n;++i) fac[i]=1ll*fac[i-1]*i%mod;
	inv[1]=1;for (int i=2;i<=n;++i) inv[i]=(1ll*mod-mod/i)*inv[mod%i]%mod;
	for (int i=1;i<=n;++i) ivs[i]=(ivs[i-1]+inv[i])%mod;
	for (int i=1;i<=n;++i) ans=(ans+(1ll*ivs[i]+ivs[n-i+1]-1)*a[i]%mod*fac[n]%mod)%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main(){
  int x, a, b, c, cnt=0;
  cin >> a >> b >> c >> x;
  for(int i=0; i<=a; i++){
    for(int j=0; j<=b; j++){
      for(int k=0; k<=c; k++){
        if(i*500 + j*100 + k*50 == x){
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int n,z,w;
  cin>>n>>z>>w;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  if(n==1){
    z=a[0];
    cout<<abs(z-w)<<endl;
    return 0;
  }
  cout<<max(abs(w-a[n-1]),abs(a[n-1]-a[n-2]))<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;
#define ll long long
#define MOD 1000000007
#define INF (int)1e9
#define EPS 1e-9
#define pb push_back
/*
    This is G. Longest Path in a graph
*/
void ade(vector<int> adj[],int t,int y){
    adj[t].pb(y); //Edge from t-y in a graph
}
int c=0;
void an(vector<int> adj[],bool vis[],int s,int dp[]){
    vis[s]=true;
    for(int i=0;i<int(adj[s].size());i++){
        if(!vis[adj[s][i]]){
            an(adj,vis,adj[s][i],dp);
        }
        dp[s]=max(dp[s],1+dp[adj[s][i]]);
    }

}
int main(){
    int n,m; cin>>n>>m;
    vector<int> adj[n+1];
    for(int i=0;i<m;i++){
        int t,y; cin>>t>>y;
        ade(adj,t,y); //This is for adding the edge to a graph
    }
    bool vis[n+1];
    memset(vis,0,sizeof(vis));
    int dp[n+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        if(!vis[i])
            an(adj,vis,i,dp);
    }
    for(int i=1;i<=n;i++){
        c=max(c,dp[i]);
    }
    cout<<c;
    return 0;
}



Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<set>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvii = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

struct SegmentTree{
    int N;
    vector<map<char,int> > dat;
    SegmentTree(int n_){
        N = 1;
        while(N < n_) N *= 2;
        dat.resize(2*N-1);
    }

    void update_init(int q, int a){
        q  = q + N - 1;
        dat[q][a]++;
        while(q>0){
            q = (q-1)/2;
            dat[q][a]++;
        }
    }

    void update(int q, char a){
        q  = q + N - 1;
        char old = dat[q].begin()->first;
        dat[q].erase(old);
        dat[q][a]++;
        while(q>0){
            q = (q-1)/2;
            if(dat[q][old] == 1)dat[q].erase(old);
            else dat[q][old]--;
            dat[q][a]++;
        }

    }

    set<char> queri(int a, int b,int k, int l, int r){ //[a,b)の文字数を調べる kは節点
        if(r <= a || b <= l){
            set<char> st; return st;
        }
        if(a <= l && r <= b){
            set<char> st;
            for(auto i = dat[k].begin(); i != dat[k].end(); i++){
                st.insert(i->first);
            }
            return st;
        }
        else{
            set<char> stl = queri(a,b, k*2+ 1, l, (l+r)/2);
            set<char> str = queri(a,b,k*2 + 2, (l+r)/2, r);
            for(auto i = str.begin(); i != str.end(); i++){
                stl.insert(*i);
            }
            return stl;
        }
    }
};

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int N,Q; string S;
    cin>>N; cin>>S; cin>>Q;
    SegmentTree seg(N);
    REP(i,S.length()){
        seg.update_init(i,S[i]);
    }
    vector<int> ans;
    REP(k,Q){
        int q; cin>>q;
        if(q == 1){
            int i;
            char c; 
            cin>>i>>c; i--;
            seg.update(i,c);
        }
        else{
            int l,r; cin>>l>>r; l--,r--;
            int push = seg.queri(l,r+1,0,0,seg.N).size();
            ans.push_back(push);
        }
    }

    REP(i,ans.size()){
        //cout << ans[i] << endl;
        printf("%d\n",ans[i]);
    }

}


Measured memory_bytes: 191672
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  ll a,b,c,k;cin >>a >>b>>c>>k;
  ll diff;
  if (k%2==0){
    diff = a-b;
  } else {
    diff = b-a;
  }
  if (abs(diff) > (ll)pow(10,18)){
    cout << "Unfair" << endl;
  } else {
    cout << diff << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int ans=0;
        for(int i =X;i<2*X+2;i++) {
    		boolean flg=true;
        	for(int j=2;j<X;j++) {
        		if(i%j==0) {
        			flg=false;
        			break;
        		}
        	}
        	if(flg==true) {
        		ans=i;
        		break;
        	}
        }

        System.out.println(ans);
        		
    }
}

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

int main(){
  ll x;
  cin >> x;

  int i=1;
  ll a, b;
  bool flag = false;
  map<ll, ll> fiveset;
  fiveset[0] = 0;

  for(;;){
    a = pow(i, 5);
    if(fiveset.find(a-x) != fiveset.end()){
        ll j = fiveset[a-x];
        cout << i << " "<< j << endl;
        break;
    }else if(fiveset.find(-a+x) != fiveset.end()){
        ll j = fiveset[-a+x];
        cout << i << " "<< -j << endl;
        break;
    }
    fiveset[a] = i;
    i++;
  }
}

Measured memory_bytes: 3996
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <sstream>
#include <string.h>
#include <iomanip>
#define ll long long
#define pb push_back
using namespace std;
 
int main()
{
int r;
cin>>r;
if(r<1200)cout<<"ABC"<<endl;
else if(r<2800)cout<<"ARC"<<endl;
else cout<<"AGC"<<endl; 
system("pause");
return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef map<ll,ll> mll;

#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
// #define mod 998244353
#define mod 1000000007 

#define trace1(x)                       cerr<<#x<<": "<<x<<endl
#define trace2(x, y)                    cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)                 cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(x, y, z , t)             cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<endl
#define trace5(x, y, z , t , u)         cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<" | "<<#u<<": "<<u<<endl
#define trace6(x, y, z , t , u , v)     cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#t<<": "<<t<<" | "<<#u<<": "<<u<<" | "<<#v<<": "<<v<<endl

#define repa(i,sta,end,inc) for(int i = sta ; i <= end ; i += inc)
#define repb(i,sta,end,inc) for(int i = sta ; i >= end ; i -= inc)

ll power(ll x , ll y , ll z){ll res = 1;x %= z;while(y){if(y&1){res = res * x % z;}x = x*x % z;y /= 2;}return res%z;}
ll gcd(ll a , ll b){return (b == 0 ? a : gcd(b , a % b));}

const int N = 2 * 100000 + 5;
const int inf = (1<<30);

void solve(){
    int n , m;
    cin >> n >> m;
    ll x , sum = 0;
    repa(i,0,m-1,1)cin >> x,sum += x;
    sum = n - sum;
    cout << (sum < 0 ? -1 : sum) << endl;

}


int main(){
    FIO;
    int T = 1;
    // cin >> T;
    repa ( i , 1 , T , 1){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
ll p[111];
ll c[111];
void solve(){
    ll d,g;
    cin>>d>>g;
    
    for(int i=0;i<d;i++)cin>>p[i]>>c[i];
    ll ans =  1e9;
    for(int i=0;i<(1<<d);i++){
        ll trt = 0;
        ll cnt = 0;
        ll lst = 0;
        for(int j=0;j<d;j++){
            if(i&(1<<j)){
                trt+=p[j]*(j+1ll)*100ll+c[j];
                cnt+=p[j];
            }
            else{
                lst = j+1;
            }
        }
        if(trt>=g){
            ans = min(ans,cnt);
        }
        else{
            int dif = g-trt;
            assert(lst>0);
            dif=(dif+lst*100-1)/(lst*100);
            if(dif<=p[lst-1]){
                ans = min(ans,cnt+dif);
            }
        }
    }
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3652
line = input()

a, b, c = [int(n) for n in line.split()]
k = int(input())

max_val = max(a, b, c)
max_val_mem = max_val

amax = False
bmax = False
cmax = False

for _ in range(k):
    max_val *= 2

if max_val_mem == a:
    amax = True
    print(str(max_val+ b+ c))
elif max_val_mem == b:
    bmax = True
    print(str(max_val+ a+ c))
elif max_val_mem == c:
    cmax = True
    print(str(max_val+ a+ b))


Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int main(){
    int n;
    cin >> n;
    int x = 1;
    while (2*x <= n) x *= 2;
    cout << x << endl;
 
    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;
using static System.Math;

class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Enumerable.Repeat(0, n).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        //全てが偶数になった状態で相手にわたれば良い
        Console.WriteLine(a.All(x => x % 2 == 0) ? "second" : "first");
    }
}


Measured memory_bytes: 16604
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-12 12:00:19
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    int ans = 0;
    for (int i = 0; i < 3; i++)
        ans += s[i] - '0';

    cout << ans << endl;

    return 0;
}


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

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

int main(){
	int n=read(),p=0;
	vi s;
	REP(i,n){
		int x=read();
		p^=x;
		s.PB(x^(x-1));
	}
	sort(ALL(s));
	reverse(ALL(s));
	int ans=0;
	for(auto v:s)if(p){
		if(__builtin_clz(p)==__builtin_clz(v)){
			p^=v;
			ans++;
		}
	}
	if(p==0)
		cout<<ans<<endl;
	else
		cout<<-1<<endl;
}


Measured memory_bytes: 892
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>


//pair sort firstに揃う

#define int long long
#define pb(n) push_back(n)
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define PairV vector<pair<int , int> >
#define F first
#define S second
#define Vector1  vector<int>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
#define PI 3.14
#define Rad2Deg  57.29578
#define INF 1000000000000

using namespace std;

int MD(pair<int,int> a,pair<int,int> b){//ManhattanDisRance
    return abs(a.first-b.first) + abs(a.second-b.second);
}
int MOD(int a,int b){
    return abs(a%b);
}

signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    incin(n);

    while (true)
    {
        if(MOD(n,-2)==0){
            s.insert(s.begin(),'0');
        }else{
            s.insert(s.begin(),'1');
        }
        n=(n-MOD(n,-2))/-2;
        if(n==0){
            break;
        }
    }
    cout<<endl;
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
import sys
input = lambda: sys.stdin.readline().rstrip()

M = 998244353
B = pow(10, 18, M)
N = int(input())

def geometric_mod(a, r, m, n):
  x = a
  for i in range(n):
    yield x
    x = (x*r)%m

BB = list(geometric_mod(1, B, M, N+2))

def ext_euc(a, b):
  x1, y1, z1 = 1, 0, a
  x2, y2, z2 = 0, 1, b
  while z1 != 1:
    d, m = divmod(z2,z1)
    x1, x2 = x2-d*x1, x1
    y1, y2 = y2-d*y1, y1
    z1, z2 = m, z1
  return x1, y1

def inv_mod(a, b, m):
  x, y = ext_euc(a, m)
  return (x * b % m)

def mex(s):
  for i in range(N+1):
    if i not in s:
      return i

def calc_grundy(e):
  g = {}
  sum_g = defaultdict(int)
  sum_g[0] = inv_mod(B-1, pow(B, N+1, M)-B, M)
  for i in range(N, 0, -1):
    if i not in e:
      continue
    m = mex({g.get(j, 0) for j in set(e[i])})
    if m:
      g[i] = m
      sum_g[g[i]] = (sum_g[g[i]] + BB[i]) % M
      sum_g[0]  = (sum_g[0] - BB[i]) % M

  return sum_g

def read_edge():
  M = int(input())
  e = defaultdict(list)
  for i in range(M):
    a, b = sorted(map(int, input().split()))
    e[a].append(b)
  return e

def solve(N, edge):
  sum_g = list(map(calc_grundy, edge))
  ret = 0
  for gx, sx in sum_g[0].items():
    for gy, sy in sum_g[1].items():
      gz = gx^gy
      sz = sum_g[2][gz]
      if sz:
        ret = (ret + sx*sy*sz) % M
  return ret


edge = [read_edge() for i in range(3)]

print(solve(N, edge))

Measured memory_bytes: 93600
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        int[] v = new int[3];
        for(int i = 0; i < 3; ++i) {
            v[i] = ReadInt();
        }
        Arrays.sort(v);
        System.out.println(v[0] + " " + v[1] + " " + v[2]);
    }
    static int ReadInt() throws IOException {
        return Integer.parseInt(sc.next());
    }
}

Measured memory_bytes: 26272
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    int W = sc.nextInt();
    if(W >= S){
      System.out.println("unsafe");
    } else {
      System.out.println("safe");
    }
  }
}

Measured memory_bytes: 35716
#include <iostream>
#define int long long

using namespace std;

signed main() {
	int x;
	cin >> x;
	
	int p = 100, cnt = 0;
	while (p < x) {
		p += p / 100;
		cnt++;
	}
	
	cout << cnt << '\n';
	
	return 0;
}

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

int bubbleSort(int A[], int N){
    int sw = 0;
    bool flag = 1;
    
    for(int i = 0; flag; i++){
        flag = 0;
        for(int j = N-1; j >= i+1; j--){
            if(A[j-1] > A[j]){
                swap(A[j-1], A[j]);
                sw++;
                flag = 1;
            }
        }
    }
    return sw;
}

int main(){
    int A[100], N, sw;
    
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    
    sw = bubbleSort(A, N);
    
    for(int i = 0; i < N; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << sw << endl;
    
    return 0;
}

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

int main() {
	int	N;
	int total;

	total = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		int l;
		int r;

		cin >> l >> r;
		while (l <= r)
		{
			total++;
			l++;
		}
	}
	cout << total << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main(){
    string W,T;
    int c=0;
    cin >> W;
    while(1){
        cin >> T;
        if(T == "END_OF_TEXT")break;
        transform(T.begin(),T.end(),T.begin(),::tolower);
        if(T == W){
            c++;
        }
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <stdio.h>
#include<stdlib.h>

int main(void)
{
	int N,i,d=0,e=0;
	unsigned long long total=1,a;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%lld",&a);
		if(a==0){total=0;e=1;d=0;}
		if(d==0&&e==0){
			if(9000000000000000000/llabs(total)>=llabs(a)){
				total*=a;
				if(1000000000000000000<total)d++;
			}else {d++;}
		}
	}
	if(d!=0)printf("-1");
	else printf("%lld",total);
	return 0;
}

Measured memory_bytes: 1732
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef double db;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=1000005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
bool check(vector<int> a){
    for(int i=0;i<a.size();i++){
        int x=a[i];
        for(int j=i+1;j<min(i+x+1,(int)a.size());j++){
            if(a[j]!=a[i+1])return false;
        }
    }
    return true;
}
int n;
int dp[max_n];
int sum=0;
int main(){
    /*
    for(int i=1;i<=3;i++){
        for(int j=1;j<=3;j++){
            for(int k=1;k<=3;k++){
                vector<int> a;a.push_back(i),a.push_back(j),a.push_back(k);
                if(check(a)){
                    for(auto x:a)cout<<x<<' ';
                    cout<<endl;
                }
            }
        }
    }
    */
    scanf("%d",&n);
    dp[0]=1;
    sum=1;
    for(int i=1;i<=n;i++){
        dp[i]=sum;
        if(i>=2)dp[i]=Sub(dp[i],dp[i-2]);
        sum=Add(sum,dp[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int res=dp[i];
        int x=max(2,n-i);
        x=n-x+1;
        if(n-i>=2)x=Add(x,Mul(n-1,n-1));
        res=Mul(res,x);
        ans=Add(ans,res);
    }
    ans=Add(ans,dp[n]);
    printf("%d\n",ans);
    return 0;
}

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

int main() {
    int a,b,i=0,j=0;
    cin>>a>>b;
    char f[a][b];
    for(i=0;i<a;i++)
    {
        for(j=0;j<b;j++)
        {
            cin>>f[i][j];
        }
    }
    for(i=0;i<b+2;i++)
    cout<<"#";
    cout<<endl;
    for(i=0;i<a;i++)
    {
    cout<<"#";
    for(j=0;j<b;j++)
            cout<<f[i][j];
    cout<<"#"<<endl;
    }
        for(i=0;i<b+2;i++)
    cout<<"#";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int N, D, X;
	cin >> N >> D >> X;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	int res = X;
	REP(i, N) {
		int j = 0;
		while (1 + j++ * A[i] <= D) res++;
	}
	cout << res << "\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);
		
		while(sc.hasNext()){
			String s = sc.next();
			Scanner sd = new Scanner(s.replaceAll(",", " "));
			double x1 = sd.nextDouble();
			double y1 = sd.nextDouble();
			double x2 = sd.nextDouble();
			double y2 = sd.nextDouble();
			double xq = sd.nextDouble();
			double yq = sd.nextDouble();
			double x, y, d, e;
			
			if(x1==x2){
				y = yq;
				x = 2*x1 - xq;
			}else if(y1==y2){
				x = xq;
				y = 2*y1 - yq;
			}else{
				d = (y2-y1)/(x2-x1);
				e = y1-d*x1;
				x = (2*yq*d-2*d*e+xq-d*d*xq)/(d*d+1);
				y = (xq-x)/d+yq;
			}
			System.out.println(x + " " + y);
		}
	}	
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,m;
  cin>>n>>m;
  vector<int> v;
  map<int,int> mp;
  rep(i,2*m){
    int a;
    cin>>a;
    v.push_back(a);
  }
  rep(i,2*m){
    mp[v[i]-1]++;
  }
  
  rep(i,n){
    cout<<mp[i]<<endl;
  }
  
}
///////////////////////////



Measured memory_bytes: 256