akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

vector<int> G[N];
int n,m;
int mem[N];

int dfs(int u)
{
    int &ret = mem[u];
    if (ret != -1) return ret;
    ret = 0;
    for(auto v:G[u])
    {
        ret = max(ret,dfs(v));
    }
    ret++;
    return ret;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);
    memset(mem,-1,sizeof mem);

    cin >> n >> m;
    REP(i,0,m-1)
    {
        int x,y;
        cin >> x >> y;
        G[x].PB(y);
    }
    int ans = 0;
    REP(i,1,n) ans = max(ans,dfs(i));
    cout << ans-1 << endl;
    return 0;
}


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

int main(){
    string str1,str2;
    int num,index;
    while(1){
        cin >> str1;
        if(str1.at(0) == '-'){
            return 0;
        }
        cin >> num;
        for(int i = 0;i < num;++i){
            cin >> index;
            str2 = str1.substr(0,index);
            str1.erase(0,index);
            str1 = str1 + str2;
        }
        cout << str1 << endl;
    }
}


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

class Program{

  static int a, b;
  static string ans;

  static int Main() {

    string[] nyu =  Console.ReadLine().Split(' ');
    a = int.Parse(nyu[0]);
    b = int.Parse(nyu[1]);

    if (a <= 8 && b <= 8) {
      ans = "Yay!";
    } else {
      ans = ":(";
    }

    Console.WriteLine("{0}", ans);

    return 0;
  }

}


Measured memory_bytes: 13140
n = int(input())
nums = list(map(int, input().split()))

flag = 0
ans = 0
for i, num in enumerate(nums):
  if i == num - 1:
    if flag:
      ans += 1 
      flag = 0
    else:
      flag = 1
  else:
    if flag == 1:
      ans += 1
      flag = 0
      
if flag == 1:
  ans += 1
  
print(ans)

Measured memory_bytes: 52908
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = 0;

    for(int i = 0;i < 2;i++) {
      if(a >= b) {
        sum += a;
        a--;
      } else {
        sum += b;
        b--;
      }
    }

    System.out.println(sum);

  }

}


Measured memory_bytes: 21716
//AtCoder ABC120 B - K-th Common Divisor
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
ll lcm(ll num1,ll num2){
    return num1 / __gcd(num1,num2) * num2;
}
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-2.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll A,B,K; cin>>A>>B>>K;
    ll v=__gcd(A,B); //vの約数
    auto tbl=divisor(v);
    cout<<tbl[tbl.size()-K]<<endl;
    return 0;
}

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

using namespace std;

int decide(string S);

int main(){
    int count = 0;
    int ans = 0;
    int i,n;
    string S;
    cin >> S;

    for(i = 0 ; i < 9 ; i++){
        count = 0;
        n = i;
        // while(decide(S[n]) == 1){
        //     count++;
        //     n++;
        // }
        while(S[n] == 'A' || S[n] == 'G' || S[n] == 'T' || S[n] == 'C' ){
            count++;
            n++;
        }

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

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

int decide(string S){
    int ans = 0;
    if(S == "A" || S == "G" || S == "T" || S == "C"){
        ans = 1;
    }
    return ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
  long long a,b;
  cin>>a>>b;
  if(a<b){
    swap(a,b);
  }
  int ok=0;
  for(long long i=0;i<a;i++){
    if(abs(a-i)==abs(b-i)){
     ok=1; 
      cout<<i<<endl;
      break;
    }
  }
  if(ok==0){
    cout<<"IMPOSSIBLE"<<endl;
  }
 return 0; 
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<pair<int, int>> task(N);
  int A, B;
  for( int i = 0; i < N; i++ ){
    cin >> A >> B;
    task.at(i) = make_pair(B, A); //締め切りを先に！！
  }
  
  sort(task.begin(), task.end());
  
  int time = 0;
  for( int i = 0; i < N; i++ ){
    time += task.at(i).second;
    if( time > task.at(i).first ){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define f(i,j,k) for(int i=j;i<k;i++)
#define f2(i,j,k) for(int i=j;i>=k;i--)
long long q1(long long a){
    if(a%2==0){
        return a/2;
    }
    else{
        return 3*a+1;
    }
}
int main(){
    long long n,ans=1;
    cin>>n;
    vector <long long> a(1000001,0);
    a[n]++;
    while(1){
        n=q1(n);
        ans++;
        if(a[n]!=0){
            break;
        }
        else{
            a[n]++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

const int MAXN = 3000;
const int MOD = 1000000000 + 7;
int dp[MAXN][MAXN];
int sum[MAXN][MAXN];

int get(int x, int y) {
    if (x < 0 || y < 0) return 0;
    return sum[x][y];
}

int upd(int &x) {
    x = ((long long)x + (long long)MOD * MOD) % MOD;
}

int update(int x, int y, int d) {
    sum[x][y] = d;
    if (x > 0) sum[x][y] += sum[x - 1][y];
    upd(sum[x][y]);
    if (y > 0)sum[x][y] += sum[x][y - 1];
    upd(sum[x][y]);
    if (x > 0 && y > 0) sum[x][y] -= sum[x - 1][y - 1];
    upd(sum[x][y]);
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> s(n);
    vector <int> t(m);
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 0; i < m; i++) cin >> t[i];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i][j] = 1;
                dp[i][j] += get(i - 1, j - 1);
                upd(dp[i][j]);
//                for (int k = 0; k < i; k++) {
//                    for (int p = 0; p < j; p++) {
//                        if (s[k] == t[p]) {
//                            dp[i][j] += dp[k][p];
//                            dp[i][j] %= MOD;
//                        }
//                    }
//                }
            }
            update(i, j, dp[i][j]);
        }
    }
    int ans = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans += dp[i][j];
            ans %= MOD;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 49408
h,w,m=list(map(int,input().split()))
b=[]
r=[0]*(3*10**5+2)
c=[0]*(3*10**5+2)
for i in range(m):
    h,w=list(map(int,input().split()))
    r[h]=r[h]+1
    c[w]=c[w]+1
    b.append([h,w])
if max(r)>max(c):
    j=r.index(max(r))
    for i in range(len(b)):
        if b[i][0]==j:
            c[b[i][1]]=c[b[i][1]]-1
else:
    i=c.index(max(c))
    for j in range(len(b)):
        if b[j][1]==i:
            r[b[j][0]]=r[b[j][0]]-1
print(max(r)+max(c))

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

int main(){
  int a,b,c,d;cin >> a >> b >> c >> d;
  while(1){
    c -= b;
    if(c <= 0){cout <<"Yes";return 0;}
    a -= d;
    if(a <= 0){cout <<"No";return 0;}
  }
  return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
//const ull mod = 1e9 + 7;
const ll mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

// conversion number to bit
string num2bit(ll num, ll len){
  string bit = "";
  REP(i, len){
    bit += char('0'+(num>>i & 1));
  }
  return bit;
}

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

    ll N, M;
    cin >> N >> M;
    vector<ll> s(M), c(M);
    REP(i, M) cin >> s[i] >> c[i];
    REP(i, M) s[i]--;

    ll lb = 1;
    REP(i, N-1) lb *= 10;
    ll ub = lb*10;
    if(N==1) lb = 0;

    for(int x=lb;x<ub;x++){
    	bool ok = true;
    	string T = to_string(x);
    	REP(i, M){
    		if(T[s[i]]-'0' != c[i]) ok = false;
    	}
    	if(ok){
    		cout << x << endl;
    		return 0;
    	}
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(1000000)
from collections import deque

# 整数の入力
N = int(input())
#配列の入力
A = list(map(int, input().split()))
ans = 0
S = [0]*N
total = sum(A)
for i in range(N):
    ans += A[i] * (total - A[i])
    total  -= A[i]

print(ans%(10**9+7))


Measured memory_bytes: 32384
def fatora(n):
	ans = []
	for i in range(1, n+1):
		if i*i > n:
			break
		else:
			if n % i == 0:
				ans.append(i)
				ans.append(n//i)
	return set(ans)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a%b)


def eh_primo(n):
	if n == 0:
		return False
	elif n == 1:
		return True
	elif n == 2:
		return True
	else:
		for i in range(2, n+10):
			if i*i > n:
				break
			else:
				if n % i == 0:
					return False
		return True



a, b = map(int, input().split())
print(len(list(filter(eh_primo, fatora(gcd(a, b))))))

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

using namespace std;

typedef long long ll;

ll md = 1000000007;


int main(int, char**)
{
	string s;
	int n, l;
	ll ans = 0;
	cin >> s;

	if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
		cout << "Bad" << endl;
	else
		cout << "Good" << endl;

	// cerr << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i;
  int res=0;
  scanf("%d",&n);
  int p[n];
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  for(i=1;i<n-1;i++){
    if((p[i-1]<p[i])&&(p[i]<p[i+1]))res++;
    if((p[i-1]>p[i])&&(p[i]>p[i+1]))res++;
  }
  printf("%d",res);
  return 0;
}

Measured memory_bytes: 128
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0)
def F(c)
	H[c].each{|e|!Z[e]?(Z[e]=Z[c]+1;F(e)):(Z[c]-Z[e])%2<1&&raise}
end
N,M=gets.split.map &:to_i
H=Hash.new{|h,k|h[k]=[]};Z={1=>0}
M.times{
a,b=gets.split.map &:to_i
H[a]<<b;H[b]<<a
}
p _=(F(1)&&Z.partition{|k,v|v%2<1}.map(&:size).reduce(:*) rescue N*~-N/2)-M

Measured memory_bytes: 54840
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.math;
import std.bigint;

void main(){
  auto qty = readInt();
  auto num = readLongs();
  
  ulong negative = num.count!("a < 0");
  bool zero = num.find(0).length ? true : false;
  
  auto pnum = num.map!(a => abs(a));
  
  auto ret = pnum.sum;
  if(!zero && negative % 2 == 1) ret -= 2 * pnum.minPos.front;
  
  writeln(ret);
}

int readInt(){
  return readln.chomp.to!int;
}

long[] readLongs(){
  return readln.chomp.split.to!(long[]);
}

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


using namespace std;

#define PI 3.14159265358979323846264338327950L


// a^2 = b^2 + c^2 - 2bc cos ang(A)

// Angle A = H + (M/60)

int main() {

	long double a, b, h, m;

	cin >> a >> b >> h >> m;
	
	// Angle
	long double angle = PI * 2 * ( (long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
	long double dist = (long double)(a * a + b * b) - (long double)(2 * a * b) * cosl(angle);


	printf("%20.20Lf\n", sqrtl(dist));

	return 0;
}

Measured memory_bytes: 4084
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n;
 
int main() {
  cin >> n;
  vector<pair<ll,ll>> p(n);
  for(ll i=0;i<n;i++){
    ll x;
    ll l;
    cin >> x;
    cin >> l;
    p[i] = make_pair(x+l,x-l);
  }
  sort(p.begin(),p.end());
  ll max;
  ll count = 0;
  for(ll j=0;j<n;j++){
    if(j==0 || max <= p[j].second){
      max = p[j].first;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1792
if __name__ == '__main__':
    s = input()
    ys = 00
    ye = 99
    ms = 1
    me = 12
    s1 = int(s[0:2])
    s2 = int(s[2:])
    yymm = False
    mmyy = False
    if (ys <= s1 <= ye) and (ms <= s2 <= me):
        yymm = True
    if (ms <= s1 <= me) and (ys <= s2 <= ye):
        mmyy = True
    if yymm and mmyy:
        print('AMBIGUOUS')
    elif yymm and not mmyy:
        print('YYMM')
    elif mmyy and not yymm:
        print('MMYY')
    else:
        print('NA')


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int V, E, s, t, d;
long long int K[101][101];
bool B[101][101];
const long long int inf = 100000000000;
int main() {
 cin >> V >> E;
 for (int i=0; i<V; ++i) {
  for (int j=0; j<V; ++j) {
   K[i][j] = (i == j) ? 0 : inf;
   B[i][j] = false;
  }
 }
 for (int i=0; i<E; ++i) {
  cin >> s >> t >> d;
  K[s][t] = d;
  B[s][t] = true;
 }
 for (int k=0; k<V; ++k) {
  for (int i=0; i<V; ++i) {
   for (int j=0; j<V; ++j) {
    if (K[i][j] > K[i][k] + K[k][j] && B[i][k] && B[k][j]) {
	 K[i][j] = K[i][k] + K[k][j];
	 B[i][j] = true;
	}
   }
  }
 }
 bool nc = false;
 for (int i=0; i<V; ++i) {
  if (K[i][i] < 0) {
   cout << "NEGATIVE CYCLE" << endl;
   nc = true;
   break;
  }
 }
 if (!nc) {
  for (int i=0; i<V; ++i) {
   for (int j=0; j<V; ++j) {
    if (K[i][j] == inf) { cout << "INF"; }
	else { cout << K[i][j]; }
    cout << ((j == V-1) ? "" : " ");
   }
   cout << endl;
  }
 }
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-3;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod
#define CHECK cout<<"arrived"<<endl

vec d,s;
ll N;

ll Solve(ll x){
    ll a=s[x]/2;
    ll b=(s[x]+s[N]+1)/2;
    ll A=lower_bound(ALL(s),a)-s.begin();
    if(abs(s[x]-2*s[A])>abs(s[x]-2*s[A-1])) A--;
    else if(A==x) A--;
    ll B=lower_bound(ALL(s),b)-s.begin();
    if(abs(s[x]+s[N]-2*s[B])>abs(s[x]+s[N]-2*s[B-1])) B--;
    else if(B==N) B--;
    vec aa(4);
    aa[0]=s[A]; aa[1]=s[x]-s[A]; aa[2]=s[B]-s[x]; aa[3]=s[N]-s[B];
    //rep(i,4) cout<<aa[i]<<' ';
    //cout<<':'<<x<<endl;
    sort(ALL(aa));
    return aa[3]-aa[0];

}

int main(){
    cin>>N;
    rep(i,N) {
        ll x; cin>>x;
        d.pb(x);
    }
    s.pb(0);
    rep(i,N) s.pb(s[i]+d[i]);
    ll ans=INF;
    REP(i,2,N-1) ans=min(ans,Solve(i));
    cout<<ans<<endl;
}

Measured memory_bytes: 4848
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var c = Input().ToInt();
		var d = Input().ToInt();
		
		if(d[1] == 1)
		{
			Console.WriteLine(1);
		}
		else
		{
			Console.WriteLine(0);
		
		}

	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
N, D = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]

count = 0

for i in range(N):
    X = XY[i][0]
    Y = XY[i][1]
    dist = X ** 2 + Y ** 2
    if dist <= D ** 2:
        count += 1

print(count)

Measured memory_bytes: 102420
#include<map>
#include<set>
#include<ctime>
#include<queue>
#include<cmath>
#include<bitset>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define mp(x,y) make_pair(x,y)
#define qmin(x,y) (x=min(x,y))
#define qmax(x,y) (x=max(x,y))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int read(){
	int ans=0,fh=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		ans=(ans<<1)+(ans<<3)+ch-'0',ch=getchar();
	return ans*fh;
}
const int maxn=2e5+100,maxm=maxn<<1;
int n,m,head[maxn],v[maxm],nex[maxm],num=1,du[maxn];
int X,Y;
inline void add(int x,int y){
	v[++num]=y,du[y]++;
	nex[num]=head[x],head[x]=num;
	v[++num]=x,du[x]++;
	nex[num]=head[y],head[y]=num;
}
bool dfs(int x,int fa){
	if(x==X) return 1;
	if(x==Y) return 0;
	for(int i=head[x];i;i=nex[i])
		if(v[i]!=fa) return dfs(v[i],x);
	return 0;
}
int main(){
	//freopen("nh.in","r",stdin);
	//freopen("zhy.out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=m;i++) add(read(),read());
	for(int i=1;i<=n;i++){
		if(du[i]%2){
			printf("No\n");
			return 0;
		}
	}
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(du[i]>4){
			printf("Yes\n");
			return 0;
		}
		if(du[i]==4){
			cnt++;
			if(cnt==1) X=i;
			else Y=i;
		}
	}
	if(cnt==1){printf("No\n");return 0;}
	if(cnt>2) printf("Yes\n");
	else{
		for(int i=head[X];i;i=nex[i])
			if(dfs(v[i],X)){
				printf("Yes\n");
				return 0;
			}
		printf("No\n");
	}
	return 0;
}










Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		out(min(ni(), ni()) + min(ni(), ni()));

	}

	/*
	 * 以下メソッド集
	 */

	public static long[] kousokusoinnsuubunkaihairetsu(long n2) {
		long[] d = new long[(int) n2];
		for (int i = 0; i < n2; i++) {
			d[i] = i;
		}
		for (int i = 2; i * i < n2; i++) {
			for (int j = i * i; j < n2; j += i) {
				if (d[j] == j)
					d[j] = i;
			}

		}

		return d;
	}

	public static void permutation(String q, String ans) {
		// Base Case
		if (q.length() <= 1) {
			System.out.println(ans + q);
		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1),
						ans + q.charAt(i));
			}
		}
	}

	static char[][] same(char[][] c, int h, int w) {

		char[][] a = new char[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				a[i][j] = c[i][j];
			}
		}
		return a;

	}

	static int countkuro(char[][] c) {

		int count = 0;
		for (char[] cc : c) {
			for (char ccc : cc) {
				if ('#' == ccc) {
					count++;
				}
			}
		}
		return count;
	}

	static void debug() {

		out("---");
	}

	static void debug(Object a) {

		out("-------");
		out(a);
		out("-------");
	}

	static int ketasuu(int n) {

		String str = "" + n;
		return str.length();
	}

	static int account(String str) {

		String target = "2";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {

		return sc.nextInt();
	}

	static long nl() {

		return sc.nextLong();
	}

	static double nd() {

		return sc.nextDouble();
	}

	static String n() {

		return sc.next();
	}

	static char[] nc() {

		return sc.next().toCharArray();
	}

	static int kaijo(int n) {

		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static long kaijo(long n) {

		debug(n);

		if (n == 0l || n == 1l) {
			return 1l;
		} else {
			return n * kaijo(n - 1l);
		}
	}

	static int fib(int n) {

		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {

		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(Object obj) {
		System.out.println(obj);
	}

	static void outn(Object obj) {
		System.out.print(obj);
	}

	static double max(double d, double e) {

		return Math.max(d, e);
	}

	static long max(long a, long b) {

		return Math.max(a, b);
	}

	static long min(long d, long e) {

		return Math.min(d, e);
	}

	static int min(int a, int b) {

		return Math.min(a, b);
	}
}

class XY {

	int h;
	int w;
	int d;

	XY(int h, int w, int d) {
		this.h = h;
		this.w = w;
		this.d = d;
	}
}


Measured memory_bytes: 35728
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

N=int(input())

ListV=list(map(int,input().split()))
ListC=list(map(int,input().split()))

ans=0

for i in range(N):
    if(ListV[i]>ListC[i]):
        ans=ans+ListV[i]-ListC[i]

print(ans)

Measured memory_bytes: 5076
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct node{
	long long num,p;
}a[100010];
int s,n;
long long ans;
bool cmp(node a,node b)
{
	return a.p<b.p;
}
int main()
{
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
	scanf("%d%d",&a[i].p,&a[i].num);
	sort(a+1,a+n+1,cmp);
	int L=1,R=n;
	int bef=-1;

	while(a[L].p<=s && a[R].p>=s)
	{
		int now;
		if(a[L].num>=a[R].num)
		{
			now=false;
			a[L].num+=a[R].num;
		}
		else
		{
			now=true;
			a[R].num+=a[L].num;
		}
		if(now!=bef)
		{
			ans+=a[R].p-a[L].p;
			bef=now;
		}
		if(a[L].num>=a[R].num) R--;
		else L++;
	}
	if(a[L].p<s) ans+=s-a[L].p;
	else ans+=a[R].p-s;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<queue>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
//include<kyawa>

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

int main() {

    long res;
    long N; cin >> N;
    
    res = 180 * (N - 2);
    
	cout << res << endl;
}

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

const int N = 100000 + 10, MOD = 1000000007;

int n, a[N];

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    // y - (n - 1 - y) == x
    // y = (x + n - 1) / 2
    // (n - 1 - y) - y == x
    // y = (n - 1 - x) / 2
    a[i] = x + n - 1;
    if (a[i] & 1) return puts("0"), 0;
    a[i] /= 2;
    a[i] = std::min(a[i], n - 1 - a[i]);
  }
  std::sort(a + 1, a + n + 1);
  int cnt = 0;
  int l = 0, r = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] != l && a[i] != r) return puts("0"), 0;
    if (a[i] == l && a[i] == r) {
      ++r;
      if (i < n) ++cnt;
    } else if (a[i] == l) {
      ++l;
    } else if (a[i] == r) {
      ++r;
    } else {
      return puts("0"), 0;
    }
  }
  int ans = 1;
  while (cnt--) ans = 2LL * ans % MOD;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 512
S = input()
slst = [[] for _ in range(len(S) + 1)]
tmp = S[0]
cnt = 0
index = 0
for i in range(len(S)):
    if tmp == S[i]:
        cnt += 1
    else:
        slst[index].append(tmp)
        slst[index].append(cnt)
        index += 1
        tmp = S[i]
        cnt = 1

slst[index].append(tmp)
slst[index].append(cnt)

dp = [0] * (len(S) + 1)
if slst[0][0] == '<':
    dp[0] = 0
else:
    dp[0] = slst[0][1]

index = 1
for i in range(len(S)):
    if slst[i] == []:
        break

    if slst[i][0] == '>':
        dp[index] = dp[index - 1] + ((slst[i][1]) * ((slst[i][1] - 1))) // 2
        index += 1
    else:
        if slst[i + 1] == []:
            dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
            index += 1
        else:
            if slst[i][1] < slst[i + 1][1]:
                tdp = slst[i + 1][1]
                for k in range(1, slst[i][1]):
                    tdp += k
                dp[index] = dp[index - 1] + tdp
                index += 1

            else:
                dp[index] = dp[index - 1] + ((slst[i][1] + 1) * ((slst[i][1]))) // 2
                index += 1


print(dp[index - 1])

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

int main(){
  	double L;
  	cin >> L;

  	cout << fixed << setprecision(6) << L * L * L / 27 << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	queue<pair<string, ll>> p;

	for (int i = 0; i < n; i++)
	{
		string s;
		ll x;
		cin >> s >> x;

		p.push(make_pair(s, x));
	}

	ll time = 0;
	while (!p.empty())
	{
		string s = p.front().first;
		ll x = p.front().second;

		if (x <= q)
		{
			time += x;
			p.pop();

			println(s << " " << time);
		}
		else
		{
			time += q;
			p.pop();

			p.push(make_pair(s, x - q));
		}
	}
}



Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define in insert
#define all(x) (x).begin(), (x).end()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    int a = 0;
    int x = n;
    while(n > 0){
        a += n % 10;
        n /= 10;
    }
    if(x % a == 0) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int k, s, ans = 0;
	cin >> k >> s;
	for (int i = 0; i <= k; ++i) {
		for (int j = 0; j <= k; ++j) {
			int r = s - i - j;
			ans += r >= 0 && r <= k;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  long sum = 0;
  for(int i = 1; i <= n; i++){
    if(!(i % 3 == 0 || i % 5 == 0)){
      sum += i;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3596
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
const int INF=int(1e9);
int n,goal;
int con[15][2];
map<int,int>dp[15];
int DP(int x,int y)
{
	if(y<=0) return 0;
	if(x<1) return INF;
	if(dp[x].count(y)) return dp[x][y];
	dp[x][y]=INF;
	for(int i=0;i<con[x][0];i++)
		dp[x][y]=min(dp[x][y],DP(x-1,y-i*x)+i);
	dp[x][y]=min(dp[x][y],DP(x-1,y-con[x][0]*x-con[x][1])+con[x][0]);
	return dp[x][y];
}
int main()
{
	scanf("%d%d",&n,&goal);
	goal/=100;
	for(int i=1;i<=n;i++)
		scanf("%d%d",&con[i][0],&con[i][1]),con[i][1]/=100;
	printf("%d\n",DP(n,goal));
	return 0;
}


Measured memory_bytes: 6144
import copy

n, k =  map(int,input().split())
s = ['R'] + list(input()) + ['L']

cnt = 0
for i in range(1,n+1):
    if s[i] == 'L' and s[i-1] == 'L':
        cnt += 1
    if s[i] == 'R' and s[i+1] == 'R':
        cnt += 1
# print(cnt)
while k > 0 and cnt < n-1:
    if n- 1 - cnt > 1:
        cnt += 2
    elif n- 1 - cnt > 0:
        cnt += 1
    k -= 1
print(cnt)


Measured memory_bytes: 81144
#include <stdio.h>
int main(void){
    while(1){
        int x,y;
        scanf("%d %d", &x, &y);
        if(x == 0 && y == 0) break;
        if(x < y){
            printf("%d %d\n", x, y);
        }else{
            printf("%d %d\n", y, x);
        }
    }
    return 0;
}



Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long double PI = 3.14159265358979323846;
const int maxSize = 2e5 + 3;

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

    int x;
    cin >> x;
    pair<ll, ll> ans;
    for (ll a = -1000; a < 1000; ++a) {
        for (ll b = -1000; b < 1000; ++b) {
            if (a == b) { continue; };
            ll dif = a * a * a * a * a - b * b * b * b * b;
            if (dif == x) {
                ans.first = a;
                ans.second = b;
                break;
            }
        }
    }
    cout << ans.first << ' ' << ans.second << '\n';

    return 0;
}


Measured memory_bytes: 3616
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    AB = LLIN(N)
    AB.sort(key=lambda x: x[1])
    now = 0
    for a, b in AB:
        if b - now >= a:
            now += a
        else:
            print("No")
            exit()
    print("Yes")
if __name__ == '__main__':
    main()

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

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

    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> s(n, 0);
    s[0] = a[0];
    map<ll, ll> mp;
    ++mp[0];
    ++mp[s[0]];
    rep1(i, n){
        s[i] = s[i-1] + a[i];
        ++mp[s[i]];
    }

    ll res = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        if(itr->second > 1) res += itr->second * (itr->second - 1) / 2; 
    }

    cout << res << endl;


    return 0;
}

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

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

    int L = A, R = A + N - 1, eat = 0;
    if (L > 0) eat = L;
    if (R < 0) eat = R;
    cout << (R + L) * (R - L + 1) / 2 - eat << endl;
}

Measured memory_bytes: 256
k=int(input())
s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[k-1])

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000

using namespace std;
typedef long long ll;
typedef pair<ll ,ll> P;
const ll mod = 1e9+7;
const long double EPS = 0.0000000001;

ll conb(ll x){
    return x*(x-1)/2;
}

ll n;
int main(){
    cin >> n;
    vector<ll>a(n);
    map<ll,ll>mp;
    rep(i,0,n){
        cin >> a[i];
        mp[a[i]]++;
    }
    map<ll,ll>mp1,mp2;
    rep(i,0,n){
        mp1[a[i]] = conb(mp[a[i]]);
        mp2[a[i]] = conb(mp[a[i]]-1);
    }
    // for(auto x:mp1){
    //     cout << x.first << " " <<x.second << endl;
    // }
    // for(auto x:mp2){
    //     cout << x.first << " " <<x.second << endl;
    // }
    ll sum = 0;
    for(auto x: mp1){
        sum += x.second;
    }
    rep(i,0,n){
        cout << sum - mp1[a[i]] + mp2[a[i]] << endl;
    }
}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    long long int N,T,i,ans=0;
    cin >> N >> T;
  //  ans=T;
    long long int t[N];
    for(i = 0; i < N; i++) {
        cin >> t[i];
        if(i >= 1) {
            if(t[i] - t[i-1] < T) {
                ans += t[i] - t[i-1];
            }else {
                ans += T;
            }
        }
    }
    ans += T;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=2000005;
const ll mod=1e9+7,inv2=5e8+4;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
ll x,y,t,fac[N];
ll qpow(ll x,ll k)
{
	ll ret=1;
	while(k){
		if(k&1) ret*=x,ret%=mod;
		x*=x; x%=mod; k>>=1;
	}
	return ret;
}
ll C(ll x,ll y)
{
	return fac[x]*qpow(fac[y], mod-2)%mod*qpow(fac[x-y], mod-2)%mod;
}
int main()
{
	fac[0]=1;
	for(int i=1; i<=N-2; i++) fac[i]=fac[i-1]*i%mod;
	cin>>x>>y;
	if((x+y)%3){
		puts("0"); return 0;
	}
	t=(x+y)/3;
	x-=t; y-=t;
	if(x<0||y<0){
		puts("0"); return 0;
	}
	printf("%lld\n",C(x+y, x));
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define pb 		push_back
#define mp 		make_pair
#define pii 	pair<int,int>
#define vi 		vector<int>
#define vii 	vector<vector<int>>;
#define vpii 	vector<pii>
#define ar 		array
#define SZ(x) 	((int)(x.size()))
#define fi 		first
#define se 		second


#define TRvi(a,it)   for(auto (it)=(a).begin(),it!=(a).end();it++) 	
#define FORV (a,x)   for(auto (x):(a))
#define FOR(i,n)	 for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) 	for(int (i)=1;(i)<=(n);++(i))
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)

#define IN(x,y) 	((y).find((x))!=(y).end())
#define ALL(t) 		t.begin(),t.end()

#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define DBG cerr << "debug here" << endl;
#define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl;
#define all(x) (x).begin(), (x).end()
#define str(s) to_string(s);

typedef long long ll;

const int INF = 1e9;

const int MINV = 1;
const int MAXV = 10;








int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll t,d,s;
    cin>>d>>t>>s;
    if(s*t<d)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
    
}



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

int main() {
	int n, k; cin >> n >> k;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	vector<int> dp(n, 0);
	REP(i, n) for (int j = max(0, i - 100); j < i; j++) {
		if (abs(a[i] - a[j]) <= k)
			dp[i] = max(dp[i], dp[j] + 1);
	}
	int res = 0;
	REP(i, n)
		res = max(res, dp[i]);
	cout << res + 1 << '\n';
	return 0;
}

Measured memory_bytes: 5644
class Dice:
    def __init__(self,dice):
        self.dice = dice
        
    
    
    def dice_num(self,a,b):
        if (a==2 and b == 4) or (a==3 and b==1) or (a==4 and b==3) or (a==1 and b== 2):
            return self.dice[0]
        elif (a==2 and b == 0) or (a==0 and b==3) or (a==3 and b==5) or (a==5 and b== 2):
            return self.dice[1]
        elif (a==4 and b == 0) or (a==0 and b==1) or (a==5 and b==4) or (a==1 and b== 5):
            return self.dice[2]
        elif (a==0 and b == 4) or (a==4 and b==5) or (a==5 and b==1) or (a==1 and b== 0):
            return self.dice[3]
        elif (a==2 and b == 5) or (a==3 and b==0) or (a==0 and b==2) or (a==5 and b== 3):
            return self.dice[4]
        else:
            return self.dice[5]
            
    
    
dice = list(map(int,input().split()))

n = int(input())
        
for _ in range(n):
    a,b = map(int,input().split())
    a_num = dice.index(a)
    b_num = dice.index(b)
    dice_2 = Dice(dice)
    print(dice_2.dice_num(a_num,b_num))


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

int main(){
  int n; cin>>n;
  vector<int> a(3*n);
  for(int i=0; i<3*n; ++i)cin>>a[i];

  sort(a.begin(), a.end());
  long long ans=0LL; int now=3*n-2;
  for(int i=0; i<n; ++i){ans+=a[now]; now-=2;}

  cout<<ans<<endl;
}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
	char S[55];
	int N, i, count = 0;
	scanf("%d", &N);
	scanf("%s", S);
	for (i = 0; i < N - 2; i++)
	{
		if (S[i] == 'A')
		{
			if (S[i + 1] == 'B')
			{
				if (S[i + 2] == 'C')
				{
					count++;
				}
			}
		}
	}
	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
// In the name of God 
#include <bits/stdc++.h>

using namespace std ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = 4000 + 10 , mod = ( int )924844033 ; 

int n , k , dp [ N ] [ N >> 1 ] , a [ N ] , ed = 1 , fact [ N ] ; 
bool mark [ N ] , head [ N ] ;

void dfs ( int v , int up ) {
	if ( mark [ v ] ++ ) return ; 
	a [ ed++ ] = v ;
	int cur = ( up ? v - n : v ) ;
	int nxt0 = cur + k , nxt1 = cur - k ;
	if ( nxt0 <= n ) {
		if ( !up ) nxt0 += n ;
		dfs ( nxt0 , up ^ 1 ) ; 
	}
	if ( nxt1 >= 1 ) {
		if ( !up ) nxt1 += n ;
		dfs ( nxt1 , up ^ 1 ) ; 
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> k ;
	for ( int i = 1 ; i <= n ; ++i ) {
		if ( !mark [ i ] ) {
			head [ i ] = true ; 
			dfs ( i , false ) ; 
		}
		if ( !mark [ i + n ] ) {
			head [ i + n ] = true ; 
			dfs ( i + n , true ) ; 
		}
	}
	/*
	for ( int i = 1 ; i <= 2 * n ; ++i ) 
		cout << a [ i ] << ' ' << head [ a [ i ] ] << '\n' ;
		cout << '\n' ; */ 
	dp [ 0 ] [ 0 ] = 1 ;
	for ( int i = 1 ; i <= 2 * n ; ++i ) {
		for ( int j = 0 ; j <= n ; ++j ) {
			dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ;
			if ( !head [ a [ i ] ] ) {
				dp [ i ] [ j ] += dp [ i - 2 ] [ j - 1 ] ;
				if ( dp [ i ] [ j ] >= mod )
					dp [ i ] [ j ] -= mod ; 
			}
		}
	}
	/*
	for ( int e = 0 ; e <= n ; ++e )
	cout << "hey " << e << ' ' << dp [ 2 * n ] [ e ] << '\n' ; */
	fact [ 0 ] = 1 ;
	for ( int j = 1 ; j < N ; ++j )
		fact [ j ] = 1LL * fact [ j - 1 ] * j % mod ;
	int res = 0 ;
	for ( int j = 0 ; j <= n ; ++j ) {
		if ( j & 1 ) {
			res -= ( 1LL * dp [ 2 * n ] [ j ] * fact [ n - j ] % mod ) ; 
		} else {
			res += ( 1LL * dp [ 2 * n ] [ j ] * fact [ n - j ] % mod ) ;
		}
		if ( res < 0 ) res += mod ;
		if ( res >= mod ) res -= mod ;
		res %= mod ; 
	}
	cout << res << '\n' ; 
}


Measured memory_bytes: 63104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= N; i += 2) if (f(i) == 8) ans++;
        System.out.println(ans);
        sc.close();
    }

    public static int f(int n) {
        int sqrt = (int) Math.sqrt(n);
        int ans = 0;
        for (int i = 1; i <= sqrt; i++)
            if (n % i == 0) {
                ans++;
                if (i * i != n) ans++;
            }
        return ans;
    }

}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 998244353;
const Int MAX = 1000;
Int fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
Int COM(Int n, Int k) {
    if (n < k || n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
Int POW(Int n, Int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) return POW(n * n % MOD, m / 2);
    return n * POW(n, m - 1) % MOD;
}
int gaussian_elimination(vector<vector<int>> &A) {
    int N = A.size(), M = A[0].size();
    int t = 0;
    for (int i = 0; i < N; i++) {
        for (; t < M; t++) {
            for (int j = i; j < N; j++) {
                if (A[j][t]) {
                    swap(A[i], A[j]);
                    break;
                }
            }
            if (A[i][t]) break;
        }
        if (t >= M) return i;
        for (int j = i + 1; j < N; j++) {
            if (j != i && A[j][t]) {
                for (int k = 0; k < M; k++) A[j][k] ^= A[i][k];
            }
        }
        t++;
    }
    return N;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    COMinit();
    int N, M; cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(M));
    for (auto &row : A) for (auto &a : row) cin >> a;
    int rank = gaussian_elimination(A);
    Int ans = 0;
    for (int i = 1; i <= rank; i++) {
        for (int j = 1; j <= i; j += 2) {
            ans = ans + COM(rank, i) * COM(i, j) % MOD * POW(2, M - i) % MOD;
        }
    }
    ans %= MOD;
    ans = ans * POW(2, N - rank) % MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
string S;

string ans = "-1";

void solve(){
    string cand[4];
    if(S[0]=='o'){
        cand[0] = "SSS";
        cand[1] = "SWW";
        cand[2] = "WSW";
        cand[3] = "WWS";
    }
    if(S[0]=='x'){
        cand[0] = "SSW";
        cand[1] = "SWS";
        cand[2] = "WSS";
        cand[3] = "WWW";
    }
    for(int i=1;i<=N-1;i++){
        for(int j=0;j<4;j++){
            if(S[i]=='o'){
                //i番目を羊と決めたなら
                if(cand[j][i+1]=='S') cand[j] += cand[j][i];
                //i番目を狼と決めたなら
                if(cand[j][i+1]=='W'){
                    if(cand[j][i]=='W') cand[j] += 'S';
                    if(cand[j][i]=='S') cand[j] += 'W';
                }
            }
            if(S[i]=='x'){
                //i番目を羊と決めたなら
                if(cand[j][i+1]=='W') cand[j] += cand[j][i];
                //i番目を狼と決めたなら
                if(cand[j][i+1]=='S'){
                    if(cand[j][i]=='W') cand[j] += 'S';
                    if(cand[j][i]=='S') cand[j] += 'W';
                }
            }
        }
    }
    for(int j=0;j<4;j++){
        if(cand[j][0]==cand[j][N] && cand[j][1]==cand[j][N+1]){
            ans = "";
            for(int i=1;i<=N;i++) ans += cand[j][i];
            return;
        }
    }
}
 
int main(){
    cin >> N;
    cin >> S;
 
    solve();

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

Measured memory_bytes: 1280
#include <iostream>

using namespace std;

int main()
{
    string S,T,U;
    int A,B;
    cin>>S>>T;
    cin>>A>>B;
    cin>>U;
    if(S==U){

        cout<<A-1<<" "<<B;
    }
    else if(T==U){
        cout<<A<<" "<<B-1;
    }
    return 0;
}

Measured memory_bytes: 256
var
  f:array[0..100000]of longint;
  n,x,i,t:longint;
Function g(x,y:longint):longint;
begin
  if x mod y=0 then exit(y) else
  exit(g(y,x mod y));
end;
begin
  readln(n,x);
  f[0]:=x;
  for i:=1 to n do
    begin
      read(f[i]);
    end;
  t:=abs(f[0]-f[1]);
  for i:=0 to n-1 do
    begin
      if f[i]<>f[i+1] then t:=g(t,abs(f[i]-f[i+1]));
    end;
  write(t);
end.

Measured memory_bytes: 512
#include <stdio.h>
int dp[2020];
int MOD = 1000000007;
int main()
{
	int n;
	scanf("%d", &n);
	dp[1] = 0;
	dp[2] = 0;
	dp[3] = 1;
	for (int i = 4; i <= n; i++)
	{
		dp[i] = (dp[i - 1] + dp[i - 3]) % MOD;
	}
	printf("%d", dp[n]);
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();

  string start_zero;
  string start_one;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      start_zero += "0";
      start_one  += "1";
    } else {
      start_zero += "1";
      start_one  += "0";
    }
  }

  int z = 0, o = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] != start_zero[i]) z++;
    if (S[i] != start_one[i]) o++;
  }
  cout << min(z, o) << endl;
  return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
string S[107]; int n, dp[107], a[107]; map<string, int>M;
int main() {
	cin >> n; for (int i = 0; i <= n; i++) { a[i] = -1; dp[i] = 9999; }
	for (int i = 0; i < n; i++) {
		while (S[i] == "")getline(cin, S[i]); dp[0] = 0;
		if (S[i].size() <= 5 || S[i][4] != ' ')M[S[i].substr(0, S[i].size() - 1)] = i;
	}
	for (int i = 0; i < n; i++) { if (S[i].size() >= 5 && S[i][4] == ' ')a[i] = M[S[i].substr(5, S[i].size() - 6)]; }
	for (int h = 0; h < n; h++) {
		for (int i = 0; i < n; i++) {
			if (a[i] >= 0) { dp[a[i]] = min(dp[a[i]], dp[i]); dp[i + 1] = min(dp[i + 1], dp[i] + 1); }
			else { dp[i + 1] = min(dp[i + 1], dp[i]); }
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 3224
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,m = LI()
if n % 2:
    for i in range(m):
        print(i+1, n-i-1)
else:
    flag = False
    for i in range(m):
        if not flag and (n-i-1) - (i+1) <= n // 2:
            flag = True
        if flag:
            print(i+1, n-i-2)
        else:
            print(i+1, n-i-1)





Measured memory_bytes: 70248
#MLE注意！0や1のケースに注意

def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    k = int(input())
    a,b = map(int, input().split())
    for i in range(a, b+1):
        if i % k == 0:
            print('OK')
            exit()
    print('NG')
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 65284