akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
ll primejudge(ll n){
  if(n<2)return 0;
  else if(n==2)return 1;
  else if(n%2==0)return 0;
  double sqrtn=sqrt(n);
  Loop(i,3,sqrtn+1){
     if(n%i==0){
        return 0;
     }
     i++;
  }
  return 1;
}
int main() {
  cout << fixed << setprecision(30);
  ll h,w,n;
  cin3(h,w,n);
  ll big=max(h,w);
  if(n%big==0)putout(n/big);
  else putout(n/big+1);
}


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

int main() {
  int n,a;
  1<=n<=1000;
  0<=a<=1000;
  cin >>n;
  cin >>a;

  if (n%500<=a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
for i in iter(input, '0 0'):
    height, width = list(map(int, i.split()))
    
    for h in range(height):
        line = ''
        for w in range(width):
            is_check = (h + w) % 2 == 0
            line += '#' if is_check else '.'
        
        print(line)
    print()


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

#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'

int main()
{
	long long n , a , b;
	
	cin >> a >> b;
	
	if( a == b)
	{
		cout << a << endl;
	}
	else if(a < b)
	{
		cout << a ;
	}
	else if( a > b)
	{
		cout << (a -1) << endl;
	}
	
	
return 0;
}




Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

bool is_number(const string &s){
  REP(i, s.size()) if(!isdigit(s[i])) return false;
  return true;
}

int main(){
  int m, n;
  string name;
  map<string, int> L, R;
  
  cin >> m;
  REP(i, m){
    cin >> name ;
    cin >>  L[name] >> R[name];
  }
  
  cin >> n;
  stack<vector<int> > st;
    
  REP(i, n){
    string exp;
    vector<int> vec(256, 0);
    
    cin >> exp;
    
    if(is_number(exp)){
      vec[atoi(exp.c_str())] = 1;
    }else if(L.find(exp) != L.end()){
      for(int i = L[exp]; i <= R[exp]; i++) vec[i] = 1;
    }else{
      vector<int> b = st.top(); st.pop();
      vector<int> a = st.top(); st.pop();

      REP(i, 256)REP(j, 256)if(a[i] && b[j]){
        
        if(exp == "+") vec[(i+j)%256] = 1;
        if(exp == "-") vec[(i-j+256)%256] = 1;
        if(exp == "*") vec[(i*j)%256] = 1;
        if(exp == "/"){
          if(j == 0) {
            cout << "error" << endl;
            return 0;
          }
          vec[(i/j)%256] = 1;
        }
      }
    }
    
    st.push(vec);
  }

  cout << "correct" << endl;
  return 0;
}

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

int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10);
    cout << W * H / 2 << endl;
    if(x == W / 2 && y == H / 2){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
#include<math.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
typedef pair<Q,ll> R;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。
//↑はあんまり気にしなくていい。



int main(){
      ll r,d,x;
      cin>>r>>d>>x;
      rep0(i,10){
            ll y=r*x-d;
            cout<<y<<endl;
            x=y;
      }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e3+10;
int s[maxn];
int sums=0;
int main()
{

    int a,b;
    cin>>a>>b;
   for(int i=1;i<=a;i++)
   {
       s[i]=i-1+b;
     //  sum[i]=sum[i-1]+s[i];
      sums+=s[i];


   }
   if(s[1]>=0)
    sums-=s[1];
   else if(s[a]<=0)
    sums-=s[a];
   else
    sums-=0;
  cout<<sums<<endl;
  // cout<<sum[a]+1044<<endl;


    return 0;
}


Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
INFI = 10**10
#input = sys.stdin.readline
import math
from collections import deque
import itertools
import heapq
#import bisect
from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint

#oo=list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
# ko=list("abcdefghijklmnopqrstuvwxyz")

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

def main():
    #l,r,d=map(int,input().split())
    n=input()
    count=0
    for i in range(len(n)):
        count+=int(n[i])
    if count%9==0:
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":

    main()


Measured memory_bytes: 73336
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if(A > B){
    if(C > A){
      cout << "No" << endl;
    }else if(C > B){
      cout << "Yes" << endl;
    }else{
      cout <<  "No" << endl;
    }
  }else{
    if(C > B){
      cout << "No" << endl;
    }else if(C > A){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
package main

import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
)

func main() {
        var s = bufio.NewScanner(os.Stdin)
        if s.Scan() {
                s.Text()
        }

        var l2 string
        if s.Scan() {
                l2 = s.Text()
        }
        var ls []int64
        for _, s := range strings.Split(l2, " ") {
                i, err := strconv.ParseInt(s, 10, 64)
                if err != nil {
                        panic(err)
                }
                ls = append(ls, i)
        }

        max := ls[0]
        var sum int64
        for _, i := range ls[1:] {
                if max >= i {
                        sum = sum + i
                        continue
                }
                sum = sum + max
                max = i
        }

        if max < sum {
                fmt.Println("Yes")
        } else {
                fmt.Println("No")
        }
}

Measured memory_bytes: 640
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt();
			long[] a = in.nextLongArray(n);

			long ans = 0;

			for (int i = 0; i < n; i++) {
				for (int j = i+1; j < n; j++) {
					ans = max(abs(a[i]-a[j]), ans);
				}
			}
			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

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

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

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

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

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

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 23380
# coding: utf-8
class Case02

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @a, @b = gets.chomp.split.map(&:to_i)
  end

  # 回答
  def solve
    #  (@a-1) * (n-1) + @a >= @b となるn
    @t = 0.upto(20) do |i|
      if (@a-1) * (i-1) + @a >= @b then
        break i
      end      
    end    
  end
  
  # 出力
  def output
    puts @t
  end

end

Case02.new.execute if $0 == __FILE__



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define fin cin
#define fout cout
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define lb lower_bound
#define right puta
using namespace std;
using namespace __gnu_pbds;
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9+7;
const int MAXN = 2e5+5;
const int MAXV = 1e6+5;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

int dp[2005];

int solve(int u) {
	if(u && u <= 2)
		return 0;
	if(!u)
		return 1;

	int &ans = dp[u];
	if(ans != -1)
		return ans;
	ans = 0;

	for(int i = 3; i <= u; i++) {
		ans += solve(u - i);
		if(ans >= mod)
			ans -= mod;
	}
	return ans;

}

int32_t main() {
	int n;
	cin >> n;
	memset(dp, -1, sizeof dp);
	cout << solve(n) << endl;
}

Measured memory_bytes: 3644
#!/usr/bin/env python3
m = int(input())
for _ in range(m):
    s = input()
    ans = set()
    for i in range(1, len(s)):
        for j in range(4):
            ans.add(s[:i][::[-1, 1][j // 2]] + s[i:][::[-1, 1][j % 2]])
            ans.add(s[i:][::[-1, 1][j // 2]] + s[:i][::[-1, 1][j % 2]])
    print(len(ans))



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll mod_pow(ll a,ll n){
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll fac[200010],finv[200010];

ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  else return (fac[n]*finv[r]%mod)*finv[n-r]%mod;
}

ll H(ll n,ll r){
  return comb(n+r-1,r);
}

ll n,k;

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

  fac[0]=1;
  rep(i,200000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,200001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>n>>k;
  ll res=0;
  repl(i,1,k+1){
    ll b=H(i,k-i);
    ll t=H(i+1,n-k-(i-1));
    cout<<b*t%mod<<endl;
  }

  return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  string s="...",ans;
  set<string>a;
  while(n--)
  { cin>>ans; a.insert(ans); }
  //if(ans.length()>n)  { ans=ans.substr(0,n); ans+=s;}
  
  //={2,4,5,7,9},b={0,1,6,8};
  /*n=n%10;
  if(a.count(n)) s="h"+s;
  else if(b.count(n)) s="p"+s;
  else s="b"+s;*/
  cout<<a.size()<<endl;
}


Measured memory_bytes: 19236
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int balls;
  int position_1, position_2, position_3;
  
  cin >> balls;
  
  position_3 = balls % 10;
  position_2 = balls % 100 / 10;
  position_1 = balls / 100;
  
  cout << position_1 + position_2 + position_3 << endl;
}

Measured memory_bytes: 256
#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 rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	int ans=0;
	while(n>0){
		if(n%10==2) ans++;
		n/=10;
	}
	cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  for(int i=1;i<=b;i++){
    if((a*i)%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
from sys import exit

L, R = map(int, input().split())

_L = L
ans = 2019
while True:
    if _L % 2019 == 0:
        if _L + 2019 <= R:
            print(0)
        else:
            print(1)
        exit()
    if _L == R:
        for i in range(L, R):
            for j in range(i + 1, R + 1):
                if ans > (i * j % 2019):
                    ans = i * j % 2019
        break
    _L += 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int h, w, n;
    cin >> h >> w >> n;
    int longer = max(h, w);
    if (n % longer == 0)
        cout << (n / longer) << endl;
    else
        cout << (n / longer + 1) << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define MOD 998244353
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;
typedef long long ll;

int main() {

    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    vector<vector<ll>> dp(C + 1, vector<ll>(D + 1, 0));

    dp[A][B] = 1;
    for (ll i = A + 1; i <= C; i++) dp[i][B] = dp[i - 1][B] * B % MOD;
    for (ll j = B + 1; j <= D; j++) dp[A][j] = dp[A][j - 1] * A % MOD;
    for (ll i = A + 1; i <= C; i++) for (ll j = B + 1; j <= D; j++) {
        dp[i][j] += dp[i - 1][j] * j;
        dp[i][j] += dp[i][j - 1] * i;
        dp[i][j] -= dp[i - 1][j - 1] * (i - 1) % MOD * (j - 1) % MOD;
        dp[i][j] += MOD;
        dp[i][j] %= MOD;
    }

    cout << dp[C][D] << endl;
    
    return 0;
}

Measured memory_bytes: 73612
#include <stdio.h>
  
void rotate_S(int minase_inori[6]) {
    int hayami_saori = minase_inori[0];
    minase_inori[0] = minase_inori[4];
    minase_inori[4] = minase_inori[5];
    minase_inori[5] = minase_inori[1];
    minase_inori[1] = hayami_saori;
}
  
void rotate_NES(int kugimiya_rie[6]) {
    int kitamura_eri = kugimiya_rie[1];
    kugimiya_rie[1] = kugimiya_rie[3];
    kugimiya_rie[3] = kugimiya_rie[4];
    kugimiya_rie[4] = kugimiya_rie[2];
    kugimiya_rie[2] = kitamura_eri;
}
  
int check(const int asumi_kana[6], const int iguti_yuka[6]) {
    int sakura_ayane;
    int satou_satomi[6];
    for (sakura_ayane = 0; sakura_ayane < 6; sakura_ayane++) {
        satou_satomi[sakura_ayane] = iguti_yuka[sakura_ayane];
    }
    for (sakura_ayane = 0; sakura_ayane < 4; sakura_ayane++) {
        int tateno_kanako;
        for (tateno_kanako = 0; tateno_kanako < 6; tateno_kanako++) {
            if (asumi_kana[tateno_kanako] != satou_satomi[tateno_kanako]) break;
        }
        if (tateno_kanako >= 6) {
            return 1;
        }
        rotate_NES(satou_satomi);
    }
    return 0;
}
  
int tokui_sora(const int utida_maaya[6], const int taneda_risa[6]) {
    int igarasi_hiromi[6];
    int horie_yui;
    for (horie_yui = 0; horie_yui < 6; horie_yui++) {
        igarasi_hiromi[horie_yui] = taneda_risa[horie_yui];
    }
    if (check(utida_maaya, igarasi_hiromi)) return 1;
    for (horie_yui = 0; horie_yui < 4; horie_yui++) {
        rotate_NES(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
        if (check(utida_maaya, igarasi_hiromi)) return 1;
        rotate_S(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
        rotate_S(igarasi_hiromi);
    }
    rotate_S(igarasi_hiromi);
    rotate_S(igarasi_hiromi);
    return check(utida_maaya, igarasi_hiromi);
}
  
int main(void) {
    int mizuhasi_kaori;
    int ootani_ikue[100][6];
    int uesaka_sumire, suzaki_aya;
    if (scanf("%d", &mizuhasi_kaori) != 1) return 1;
    for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
        for (suzaki_aya = 0; suzaki_aya < 6; suzaki_aya++) {
            if (scanf("%d", &ootani_ikue[uesaka_sumire][suzaki_aya]) != 1) return 1;
        }
    }
    for (uesaka_sumire = 0; uesaka_sumire < mizuhasi_kaori; uesaka_sumire++) {
        for (suzaki_aya = uesaka_sumire + 1; suzaki_aya < mizuhasi_kaori; suzaki_aya++) {
            if (tokui_sora(ootani_ikue[uesaka_sumire], ootani_ikue[suzaki_aya])) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
    return 0;
}



Measured memory_bytes: 2132
#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<long long int> vlli;
typedef pair<int,int> pii;
typedef pair<long long int,long long int> plli;
typedef vector< vi > vvi ;
typedef vector< vlli > vvlli  ;
#define fi(i,a,b) for(int i=a;i<=b;i++)
#define flli(i,a,b) for(long long int i=a;i<=b;i++)
#define bi(i,a,b) for(int i=a;i>=b;i--)
#define blli(i,a,b) for(long long int i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pi 2*acos(0.0)
#define pb push_back
#define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
#define present(v,num) (v.find(num)!=v.end())
#define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
#define pq priority_queue
#define mp make_pair
const int inf=INT_MAX;
const lli INF =LLONG_MAX;
const lli mod = 1e9+7;
lli gcd(lli a, lli b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    lli n;scanf("%lld",&n);
    vlli a(n);flli(i,0,n-1)scanf("%lld",&a[i]);
    //check if its setwise coprime

    vector<bool> vis(1000001,true);
    vis[0]=false;
    vis[1]=false;
    vvlli ans(1000001);
    flli(i,2,1000000)
    {
    	if(vis[i])
    	{
    		ans[i].pb(i);
    		for(lli j=2*i;j<=1000000;j+=i)
    		{
    			vis[j]=false;
    			ans[j].pb(i);
    		}
    	}
    }
    vlli pcount(1000000,0);
    bool flag=true;
    flli(i,0,n-1)
    {
    	tr(ans[a[i]],it)
    	{
    		if(pcount[*it]!=0)
    		{
    			flag=false;
    		}
    		pcount[*it]++;
    	}
    }
    lli setwise=1;
    if(!flag)
    {
    	flli(i,2,1000000)
    		if(pcount[i]==n)setwise=setwise*i;
    }
    if(flag)printf("pairwise coprime");
    else if(setwise==1)printf("setwise coprime");
    else printf("not coprime");
    return 0;
}

Measured memory_bytes: 89064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c; cin >> a >> b >> c;
  int idx = 0;
  while(1){
    if((a|b|c)&1){
      cout << idx << endl;
      return 0;
    }
    if(idx >= 1000000)break;
    int x = (b + c) / 2;
    int y = (a + c) / 2;
    int z = (a + b) / 2;
    a = x; b = y; c = z;
    idx++;
  }
  cout << -1 << endl;
}


Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    n = len(s)
    m13 = [0,10,7,4,1,11,8,5,2,12,9,6,3]
    dp = [0]*13
    mod = 10**9+7
    dp[0] = 1
    for i in s:
        dpp = dp*1
        if i == "?":
            dp = [0]*13
            for j in range(13):
                for k in range(10):
                    nj = m13[j]+k
                    dp[(m13[j]+k)%13] = (dp[(m13[j]+k)%13]+dpp[j])%mod
        else:
            ii = int(i)
            for j in range(13):
                dp[(m13[j]+ii)%13] = dpp[j]
    print(dp[5])
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 69952
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> dp(h, vector<int>(w, inf));
  dp[0][0] = (s[0][0] == '.' ? 0 : 1);
  rep(i, h) {
    rep(j, w) {
      if (i + 1 != h) {
        if (s[i][j] == '.' && s[i + 1][j] == '#') chmin(dp[i + 1][j], dp[i][j] + 1);
        else chmin(dp[i + 1][j], dp[i][j]);
      }
      if (j + 1 != w) {
        if (s[i][j] == '.' && s[i][j + 1] == '#') chmin(dp[i][j + 1], dp[i][j] + 1);
        else chmin(dp[i][j + 1], dp[i][j]);
      }
    }
  }
  cout << dp[h - 1][w - 1] << '\n';






  
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l;
    cin >> n >> l;
    vector<string> s(n);
    for(int i=0; i<n; i++){
        cin >> s[i];
    }
    sort(s.begin(),s.end());

    string min;
    for(int i=0; i<n; i++){
        min +=s[i];
    }
    cout << min << endl;
}




Measured memory_bytes: 3672
n = int(input())
x = [int(i) for i in input().split()]
l, r = x[0], x[0]
for i in x:
    l = min(l, i)
    r = max(r, i)
ans = 10e9
for i in range(l, r + 1):
    cost = 0
    for j in range(n):
        cost += (x[j] - i) ** 2
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  int t,a,b;
  cin >> t >> a >> b;
  int plan_a = t*a;
  int plan_b = b;
  if(plan_a < plan_b){
    cout << plan_a << endl;
  }else{
    cout << plan_b << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back

const int P = 1000000007;

using namespace std;

int n, m, x, c[20], a[20][20];

int main(){

	cin >> n >> m >> x;
	for(int i=0; i<n; i++){
		cin >> c[i];
		for(int j=0; j<m; j++) cin >> a[i][j];
	}

	int ans = 1e9;

	for(int b=0; b<(1<<n); b++){
		int cost = 0;
		vector<int> tmp(m, 0);
		for(int i=0; i<n; i++){
			if((b>>i)&1){
				cost += c[i];
				for(int j=0; j<m; j++) tmp[j] += a[i][j];
			}
		}
		bool ok = 1;
		for(int j=0; j<m; j++) if(tmp[j] < x) ok = 0;
		if(ok) ans = min(ans, cost);
	}

	if(ans == 1e9) cout << "-1\n";
	else cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	int cnt = 0, ans = 0, tmp, end;;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'A' && cnt == 0) {
			cnt++;
			tmp = i;
		}
		if (s[i] == 'Z') {
			end = i;
		}
	}
	cout << end - tmp + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include"iostream"
#include"vector"
#include"algorithm"
using namespace std;

int main() {
    vector<int> num;
    int n;

    for (int i = 0; i < 10; i++) {
        cin >> n;
        num.push_back(n);
    }

    sort(num.begin(), num.end(), greater<int>());

    for (int i = 0; i < 3; i++) 
        cout << num[i] << endl;
}

Measured memory_bytes: 1216
import java.util.*;
class Main{
  static int n=0;
  static int fibonacci[];
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    n = sc.nextInt();
    fibonacci = new int[n];
    if(n >= 1){
      fibonacci[0] = 1;
    }
    if(n >=2){
      fibonacci[1] = 2;
    }
    for(int i = 2; i<n; i++){
      fibonacci[i] = fibonacci[i-1]+fibonacci[i-2];
    }
    // System.out.println(Fibonacci(n-1));
    System.out.println(fibonacci[n-1]);

  }

  static int Fibonacci(int n){
    if(n == 0) return fibonacci[0];
    if(n == 1) return fibonacci[1];
    fibonacci[n] = Fibonacci(n-1) + Fibonacci(n-2);
    return fibonacci[n];
  }
}


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

using namespace std;
using ll = long long;

//dp[i] - TRUE if the first player wins if there are i stones remaining

int main()
{  
    int n,k;
    scanf("%d%d",&n,&k);
    vector<int> a(n);
    for(int& x : a){
        scanf("%d",&x);
    }
    vector<bool> dp(k+1);
    for(int stones=0; stones<=k; stones++){
        for(int x:a){
            if(stones >= x && !dp[stones - x]){
                dp[stones] = true;
            }
        }
    }
    puts(dp[k] ? "First" : "Second");
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	
	ll n;
	cin >> n;
	ll ans = 1;
	vector<ll> a(n);
	int flg = 1;
	for(ll i = 0; i < n; i++) {
		cin >> a[i];
		if(a[i] == 0) flg = 0;
	}
	if(flg == 0) {
		puts("0");
		return 0;
	}
	for(ll i = 0; i< n; i++) {
		if(ans > 1000000000000000000 / a[i]) {
			puts("-1");
			return 0;
		}
		ans *= a[i];
		
	}
	cout << ans <<endl;
}

Measured memory_bytes: 4044
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[][] result = null;
		for (int t = 0; t < n; t++) {
			char[] train = s.next().toCharArray();
			if (train.length > 1) {
				result = createTrainGraph(train);
				/* 先頭車両を決定する */
				int next = NO_CONNECTION;
				for (int i = 0; i < result.length; i++) {
					if (result[i][0] == NO_CONNECTION
							&& result[i][1] != NO_CONNECTION) {
						next = i;
					}
				}
				/* 出力 */
				while (next != -1) {
					System.out.printf("%c", next + 'a');
					next = result[next][REAR];
				}
				System.out.println();
			} else {
				System.out.println(train[0]);
			}
		}
	}

	static final int FRONT = 0;
	static final int REAR = 1;
	static final int NO_CONNECTION = -1;

	static int[][] createTrainGraph(char[] input) {
		int[][] train = new int[26][2];
		for (int i = 0; i < train.length; i++) {
			for (int j = 0; j < train[0].length; j++) {
				train[i][j] = NO_CONNECTION;
			}
		}
		boolean front = false;
		int before = input[0];
		for (int i = 1; i < input.length; i++) {
			int current = input[i];
			if ('a' <= current && current <= 'z') {
				if (front) {
					train[before - 'a'][FRONT] = current - 'a';
					train[current - 'a'][REAR] = before - 'a';
				} else {
					train[before - 'a'][REAR] = current - 'a';
					train[current - 'a'][FRONT] = before - 'a';
				}
				before = current;
			} else if (current == '>') {
				front = false;
			} else if (current == '<') {
				front = true;
			}
		}
		return train;
	}
}

Measured memory_bytes: 24448
input_nk = gets.chomp
n,m = input_nk.split.collect{ |item| item.to_i}
alist = gets.chomp.split.collect{ |item| item.to_i}
result = Hash.new(0)#Array.new(n+1).map{ 0}
alist.each do |i|
  result[i] += 1
end
blist = []
clist = []
m.times do |i|
  b,c = gets.chomp.split.collect{ |item| item.to_i}
  result[c] += b
end

sum = 0
count = 0
data = result.sort{ |(k1,v1),(k2,v2)| k2 <=> k1}
data.each do |one|
  sum += one[0] * one[1]
  count += one[1]
  if count >= n
    sum -= one[0]* (count-n)
    break
  end
end
puts sum

Measured memory_bytes: 29408
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N, K; cin >> N;
  vector<char> S(N);
  for (int i=0; i<N; i++) cin >> S[i];
  cin >> K;

  char c;
  c= S[K-1];
  for (int i=0; i<N; i++) if (S[i] != c) S[i]='*';
  for (int i=0; i<N; i++) cout << S[i];
  cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n;
int main() {
	FAST
	cin >> n;
	vector <int> a(n);
	vector <pi> ans;
	for (int i =0;i<n;i++) cin >> a[i];
	auto maxn = max_element(a.begin(),a.end());
	auto minn = min_element(a.begin(),a.end());	
	int maxp = maxn - a.begin() + 1, minp = minn - a.begin() + 1;
	
	if (abs(*maxn) >= abs(*minn)) {
		for (int i =1;i<=n;i++) ans.push_back(pi(maxp,i));
		for (int i =2;i<=n;i++) ans.push_back(pi(i-1,i));
		
	} else if (abs(*maxn) < abs(*minn)) {
		for (int i = 1;i<=n;i++) ans.push_back(pi(minp,i));
		for (int i =n-1;i >= 1; i--) ans.push_back(pi(i+1,i));
	}
	cout << ans.size() << "\n";
	for (auto cur: ans) cout << cur.f << " "<< cur.s << "\n";
	
}	



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scan_init()
	n := scanInt()
	a := make([]int, n)
	x := make([][]int,n)
	y := make([][]int,n)
	for i:= 0; i<n; i++ {
		a[i] = scanInt()
		x[i] = make([]int,a[i])
		y[i] = make([]int,a[i])
		for j:=0; j<a[i]; j++ {
			x[i][j] = scanInt() - 1
			y[i][j] = scanInt()
		}
	}
	sum := 0
	for i := 0; i < (1<<n); i++ {
		maybeHuman := make([]int,n)
		// expressHuman := map[int]int{}
		maybesum := 0
		hatan := false
		// 1をNから左シフト
		// bit全探索
		// cost := 0
		// fmt.Println("Start!!", i)
		for j := 0; j<n; j++ {
			if (i>>j&1) == 1 {
				// fmt.Println("maybe...", j)
				maybeHuman[j] = 1
			}
		}
		for j := 0; j<n; j++ {
			if (i>>j&1) == 1 {
				// fmt.Println("maybe...", j)
				for k:= 0; k<a[j]; k++ {
					if maybeHuman[x[j][k]] == 1 && y[j][k] == 0 {
						hatan = true
					}
					if maybeHuman[x[j][k]] == 0 && y[j][k] == 1 {
						hatan = true
					}
				}
			}
		}
		for _,val := range maybeHuman {
			if val == 1 {
				maybesum ++
			}
		}
		if (sum < maybesum) && !hatan {
			// fmt.Println(i, maybeHuman, "replace sum")
			sum = maybesum
		}
	}
	fmt.Println(sum)
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 200000)

func readLine() string {
	buf := make([]byte, 0, 200000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func readLineToNumber() int {
	S := readLine()
	number, _ := strconv.Atoi(S)
	return number
}
func readLineToSlice() []string {
	S := readLine()
	list := strings.Split(S, "")
	return list
}
func readLineToNumberSlice(memo map[string]int) []int {
	// err時は-1を代入
	S := readLine()
	intList := make([]int, len(S))
	for i := 0; i < len(S); i++ {
		if val, ok := memo[string(S[i])]; ok {
			intList[i] = val
		} else {
			intList[i] = -1
		}
	}
	return intList
}

Measured memory_bytes: 5680
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  string s;
  cin >> s;
  if(s.at(0)==s.at(2))cout<<"Yes"<<endl;
    else{cout<<"No"<<endl;}
 
  return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

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

	ll sum = 0;
	rep(i, N)sum += A[i];

	ll cnt = 0;
	rep(i, N) {
		if (4 * M * A[i] >= sum) cnt++;
	}

	if (cnt >= M)cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

typedef long long ll;

const int nax = 1e7+7;
const int MOD = 1e9+7;

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    cout<<endl;
}

int main(){
    int n, m; cin>>n>>m;

    vector<int> switch_counts(m);

    vector<vector<int> > switches(m);

    vector<int> p(m);

    for(int i=0; i<m; i++){
        cin>>switch_counts[i];
        for(int sw=0; sw<switch_counts[i]; sw++){
            int x; cin>>x;
            x--;
            switches[i].push_back(x);
        }
    }

    for(int i=0; i<m; i++){
        cin>>p[i];
    }

    int ans = 0;

    // n switches ... so 2^n states of switches
    for(int mask=0; mask < (1<<n); mask++){
        vector<int> curr_switches(n, 0);
        for(int i=0; i<n; i++){
            if(mask>>i & 1){
                curr_switches[i] = 1;
            }
        }

        // cout<<"mask: "<<mask<<"  switches-> ";
        // printarr(curr_switches);

        int satis = 0;
        for(int bulb=0; bulb<m; bulb++){
            int cnt = 0;
            for(int sw=0; sw<switch_counts[bulb]; sw++){
                if(curr_switches[switches[bulb][sw]] > 0){
                    cnt++;
                }
            }
            if(cnt%2==p[bulb]){
                satis++;
            }
        }
        if(satis==m){
            // cout<<"mask: "<<mask<<endl;
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  
ll dig[12];
int main()
{
	ios
	ll n,k,i,j,f=0;
	vi v;
	cin>>n>>k;
	for(i=0;i<k;i++){
		cin>>j;
		dig[j]=1;
	}
	string s=to_string(n);
	for(i=0;i<s.size();i++){
		if(f){
			for(j=0;j<10;j++)if(!dig[j]){
				v.pb(j);break;
			}
		}else{
			ll ff=0;
			for(j=s[i]-'0';j<=9;j++){
				if(dig[j]==0){
					v.pb(j);
					ff=1;
					if(j!=s[i]-'0')f=1;
					break;
				}
			}
			if(!ff){
				f=2;break;
			}
		}
	}
	if(f==2){
		for(j=1;j<10;j++)if(!dig[j]){
			cout<<j;break;
		}
		for(i=0;i<s.size();i++)
			for(j=0;j<10;j++)if(!dig[j]){
				cout<<j;break;
			}
	}else
	for(auto i:v)cout<<i;
	return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(c - (a - b) > 0) {
    cout << c - (a - b) << endl;
  }
  else {
    cout << 0 << endl;
  }
}

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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>void add(T &a, const T &b){a += b; a %= mod;}

signed main(){
  int n, k; cin >> n >> k;
  vi v(n); rep(i,n) cin >> v[i];

  vi imos(n+1);
  rep(i,n){
    imos[i+1] = imos[i] + v[i];
  }
  dump(imos);
  int ans = 0;
  FOR(i,1,min(k+1,n+1)){ // i個取る
    rep(j,i+1){ // 左からj個取る
      int tmp = imos[j]-imos[0]+imos[n]-imos[n-(i-j)];
      priority_queue<int> q;
      rep(l,j){
	if(v[l] < 0) q.push(v[l]);
      }
      FOR(l,n-(i-j),n){
	if(v[l] < 0) q.push(v[l]);
      }
      while(q.size() > k-i) q.pop();
      while(!q.empty()){
	tmp -= q.top();
	q.pop();
      }
      chmax(ans,tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> /**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
ll oo = 1e16+1;
const int nax = 3003;
int n;
ll a[nax];
ll dp[nax][nax][3];
ll go(int l, int r, int f){
	if( l > r ) return 0;
	if(dp[l][r][f] != -1) return dp[l][r][f];
	ll& ans = dp[l][r][f];
	if(f){
		ans = oo;
		ans = min(ans, go(l+1,r,f^1)-a[l]);
		ans = min(ans, go(l,r-1,f^1)-a[r]);
	}else{
		ans = -oo;
		ans = max(ans, go(l+1,r,f^1)+a[l]);
		ans = max(ans, go(l,r-1,f^1)+a[r]);
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	ms(dp,-1);
	cin>>n;
	for(int i=0; i<n; i++)
		cin>>a[i];
	cout<<go(0,n-1,0)<<endl;
 	return 0;
}


Measured memory_bytes: 211840
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(k<=a)
    {
        cout<<k<<endl;
    }
    else if((k>a)&&(k<=a+b))
    {
        cout<<a<<endl;
    }
      else if(k>a&&(k>(a+b)))
    {
        ll x=k-a-b;
        cout<<a-x<<endl;
    }
    return 0;
}




Measured memory_bytes: 3632
# & C:/Python38/python.exe c:/Users/kenta.aoyama/Desktop/work/accounts/aoj/icpc/otomori.py

#
while True:
    persons = int(input())
    if persons == 0: break

    receivedlist = []
    for i in range(persons):
        target = list(map(int, input().split()))
        target = target[1:]
        target = set(target)
        receivedlist.append(target)
 
    target = list(map(int, input().split()))
    target = set(target[1:])

    answer = []
    for i in range(len(receivedlist)):
        received_set = receivedlist[i]
        diff = target - received_set
        if not diff: answer.append(i+1)

    if len(answer) == 1:
        print(answer[0])
    else:
        print(-1)



Measured memory_bytes: 6312
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int  K,S;
  cin >> K >> S;
  int count=0;
  rep(i,K+1){
    rep(j,K+1){
      if(0<=S-i-j && S-i-j<=K){count++;}
    }
  }
  cout <<  count << endl;
}





Measured memory_bytes: 256
n, m = map(int, input().split())
cnt = [1] * n
exist = [False] * n
exist[0] = True
for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if exist[x]:
        exist[y] = True
        if cnt[x] == 1:
            exist[x] = False
    cnt[x] -= 1
    cnt[y] += 1
print(exist.count(True))

Measured memory_bytes: 48260
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>

using namespace std;

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


int main(){
    ll H, W;    cin >> H >> W;

    ll res = min(H*(H % 3 != 0), W*(W % 3 != 0));


    for(int i = 1; i <= H; i++){
        ll S_max = max(i*W, (W-W/2)*(H-i));
        ll S_min = min(i*W, (W/2)*(H-i));
        res = min(res, S_max - S_min);
    }

    for(int i = 1; i <= W; i++){
        ll S_max = max(i*H, (H-H/2)*(W-i));
        ll S_min = min(i*H, (H/2)*(W-i));
        res = min(res, S_max - S_min);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  ll ans = 0;
  rep(i, n) {
    ll x, a, b;
    cin >> x;
    a = 2*x;
    b = 2*abs(k - x);
    ans += min(a, b);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256