akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include<pair>
using namespace std;

typedef long long ll;
typedef int ii;
//typedef vector<ll> vi;

#define INF 1000000007

#define pi 3.141592654

#define T while(t--)
#define for2(i,a,b) for(i=a;i>=b;i--)
#define for3(i,a,b) for(i=a;i<=b;i=i+2)
#define for1(i,a,b) for(i=a;i<=b;i++)
#define pb push_back
#define mp make_pair

#include<sstream>

#define si set<ll>
#define se multiset<ll>

typedef long double ld;

typedef vector<ll> vi;

#define bb(arr,nn,xx) upper_bound(arr,arr+nn,xx)-arr
#define aa(arra,nna,xxa) lower_bound(arra,arra+nna,xxa)-arra

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

ii main()
{

    ios::sync_with_stdio(0);
    cin.tie(0);

    ld d,t,s; cin>>d>>t>>s; ld x=d/s;
    
    if(x<=t) cout<<"Yes"<<"\n";
    
    else cout<<"No"<<"\n";
    
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t h, w;
  cin >> h >> w;
  if(h==1 || w==1)cout << 1;
  else if(h*w%2==0)cout << h*w/2;
  else cout << h*w/2+1;
  return 0;
}


Measured memory_bytes: 3588
{-# LANGUAGE OverloadedStrings #-}
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe
import Data.String
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as BS
---------------------------------------------------------------------------------
main = do
  nab <- getIntListl'
  s <- getLine
  judge nab s

judge nab s = putStrLn . unlines . reverse . judge' nab s [] $(0,0)

judge' _ [] result _ = result
judge' nab@[_,a,b] (x:xs) result (j,f)
  |x=='a' && j+f < a+b           = judge' nab xs ("Yes":result) (j+1,f)
  |x=='b' && j+f < a+b && f < b  = judge' nab xs ("Yes":result) (j,f+1)
  |otherwise                     = judge' nab xs ("No" :result) (j,f)


  
---------------------------------------------------------------------------------

{-ByteString関連-}
--IO
getLine' = BS.getLine
getContents' = BS.getContents
getInt' = fst . fromJust . BS.readInt <$> getLine'
getIntListl' = map (fst . fromJust. BS.readInt) .BS.words <$> getLine'
getIntListc' = map (fst . fromJust. BS.readInt) .BS.words <$> getContents'
getInteger' = fst . fromJust. BS.readInteger <$> getLine'
putStr' = BS.putStr
putStrLn' = BS.putStrLn
--演算子
bs1 |++| bs2 = BS.append bs1 bs2
chr |:+| bs2 = BS.cons chr bs2
bs1 |+:| chr = BS.snoc bs1 chr

{-elem関連-}
--elemの第一引数をリストにしたもの。
--elemList "abc" "atcoder" -> [True,False,True]
elemList [] _ = []
elemList (x:xs) list  = elem x list : elemList xs list

--elemIndexの第一引数をリストにしたもの。
elemIndexList [] list = []
elemIndexList (x:xs) list  = elemIndex x list : elemIndexList xs list

--elemIndicesの第一引数をリストにしたもの。
elemIndicesList [] list = []
elemIndicesList (x:xs) list  = elemIndices x list : elemIndicesList xs list

Measured memory_bytes: 13256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

class BitSum:
    def __init__(self, n):
        self.n = n + 1
        self.table = [0] * self.n

    def add(self, i, x):
        i += 1
        while i < self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    md=998244353
    n=II()
    xy=LLI(n)
    yy=set()
    for x,y in xy:yy.add(y)
    ytoj={y:j for j,y in enumerate(sorted(yy))}

    ans=n*(pow(2,n,md)-1)-4*(pow(2,n,md)-1-n)
    ans%=md

    xy.sort()
    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    bit=BitSum(200005)
    for i,[x,y] in enumerate(xy[::-1]):
        j=ytoj[y]
        c=bit.sum(j-1)
        ans+=pow(2,c,md)-1
        ans+=pow(2,i-c,md)-1
        ans%=md
        bit.add(j,1)

    print(ans)

main()

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

int l [100010], r [100010], dp [100010] [2] ;

int main ( )  {
	int n, cnt ( 0 ) ;
	scanf ( "%d", & n ) ;
	
	for ( int i = 1 ; i <= n ; ++ i )  {
		static int x ;
		scanf ( "%d", & x ) ;
		l [i] = 63 - __builtin_clzll ( x ), r [i] = l [i] + ( ( 1 << l [i] ) != x ) ;
		cnt += r [i] ;
		dp [i] [0] = std :: max ( dp [i- 1] [0] + std :: min ( r [i - 1], l [i] ), dp [i - 1] [1] + std :: min ( l [i - 1], l [i] ) ) ;
		dp [i] [1] = std :: max ( dp [i -1] [0] + std :: min ( r [i - 1], r [i] ), dp [i - 1] [1] + std :: min ( l [i - 1], r [i] ) ) ;
	}

	return printf ( "%d\n", cnt - std :: max ( dp [n] [0], dp [n] [1] ) ), 0 ;
}


Measured memory_bytes: 1792
# include "iostream"
# include "cstdio"
# include "algorithm" 

using namespace std;

const int maxm=1e5+10; 
int n,m,ans; 

struct ask{
	int Left; 
	int Right;
	bool operator <(const ask &x)const{
		return Right<x.Right; 
	} 
}Ask[maxm]; 

int main(){
	register int i,now;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++){
		scanf("%d%d",&Ask[i].Left,&Ask[i].Right); 
	}
	sort(Ask+1,Ask+1+m);
	now=Ask[1].Right;
	for(i=1;i<=m;i++){
		if(Ask[i].Left<now) continue;
		now=Ask[i].Right;
		ans++; 
	}
	printf("%d",ans+1); 
	return 0; 
}

Measured memory_bytes: 1024
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main (String [] args){
		//		String [][] boad = new String[4][4];
		int n = Integer.parseInt(sc.next());
		List <Integer> list = new ArrayList<Integer>();
		int b = 0;
//		int c = 0;
		String d = null;
		for(int i = 0;i<n;i++){
			list.add(Integer.parseInt(sc.next()));
		}
		Collections.sort(list);
		b = list.get(list.size()-1)/2;
		for(int i = 0;i<n-1;i++){
			b += list.get(i);
		}
		System.out.println(b);
		System.out.flush();
		sc.close();
	}
}

Measured memory_bytes: 22996
//53
#include<iostream>

using namespace std;

int main(){
  for(int L;cin>>L,L;){
    int m=0;
    for(int i=1;i<=12;i++){
      int M,N;
      cin>>M>>N;
      L-=M-N;
      if(m==0&&L<=0){
	m=i;
      }
    }
    if(m){
      cout<<m<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }
  return 0;
}
  

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

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

    int h, w;

    cin >> h >> w;

    V<string> grid(h);
    bool is;

    int i, j, len;

    rep(i, h) cin >> grid[i];

    rep(i, grid.size()) {
        is = false;

        rep(j, w) {
            if (grid[i][j] != '.') is = true;
        }

        if (!is) {
            grid.erase(grid.begin() + i);
            i--;
        }
    }

    len = grid[0].size();
    rep(i, len) {
        is = false;

        rep(j, grid.size()) {
            if (grid[j][i] != '.') is = true;
        }

        if (!is) {
            rep(j, grid.size()) grid[j].replace(i, 1, "");
            len--;
            i--;
        }
    }

    rep(i, grid.size()) Out(grid[i]);

    return 0;
}


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

    dp = [float('inf')] * (N + 10)
    dp[0] = 0
    
    for i in range(1, N+1):
        power = 1
        while(power <= i):
            dp[i] = min(dp[i], dp[i-power] + 1)
            power *= 6

        power = 1
        while(power <= i):
            dp[i] = min(dp[i], dp[i-power] + 1)
            power *= 9

    print(dp[N])

main()

Measured memory_bytes: 44112
h, w = gets.split.map(&:to_i)
ss = []
h.times do
  ss << gets.chomp.chars
end

ans = 'Yes'
(0..h-1).each do |j|
  (0..w-1).each do |i|
    next unless ss[j][i] == "#"
    cnt = 0
    (0..3).each do |x|
      ny = j + [-1,0,1,0][x]
      nx = i + [0,-1,0,1][x]
      next if ny < 0 || ny > h-1 || nx < 0 || nx > w-1
      if ss[ny][nx] == "#"
        cnt += 1
      end
    end
    if cnt == 0
      ans = 'No'
    end
  end
end

puts ans

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

#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define IN(i,l,r) (l<i&&i<r) //the next for are for checking bound
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)

#define F(i,L,R) for (int i = L; i < R; i++) //next four are for "for loops"
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define FF(i,L,R) for (int i = L; i > R; i--)
#define FFE(i,L,R) for (int i = L; i >= R; i--)

#define getI(a) scanf("%d", &a) //next three are handy ways to get ints, it's also force you to use '&' sign
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)

#define wez(n) int (n); scanf("%d",&(n)) //handy if the input is right after the definition of a variable
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))

#define whileZ int T; getI(T); while(T--)
#define lastEle(vec) vec[vec.size()-1]
#define SZ(x) ((int)((x).size()))

#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) // traverse an STL data structure

#define ALL(c) (c).begin(),(c).end() //handy for function like "sort()"
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int

#define mp make_pair
#define fi first
#define se second

// for debug
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
#define printV(a) printA(a,0,a.size()-1)

#define pb push_back
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;

ll mod = 1000000007LL;

int a[22][22];
ll dp[22][1<<22];
int n;

ll getans (int i, int mask)
{
    if (!i) return ((mask==((1<<n)-1))?1LL:0LL);
    if (dp[i][mask]!=-1) return dp[i][mask];
    dp[i][mask] = 0LL;
    F(j,0,n) {
        if ( a[i-1][j] && (!(mask&(1<<j))) )
            dp[i][mask] = (dp[i][mask] + getans(i-1,mask|(1<<j))) % mod;
    }
    return dp[i][mask];
}

int main()
{
    cin >> n;
    memset(dp,-1,sizeof(dp));
    F(i,0,n) F(j,0,n) cin >> a[i][j];
    cout << getans (n,0) << "\n";
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<char> S(N);
    for (int i = 0; i < N; i++){
        cin >> S.at(i);
    }
    int x = 0, x_fin = 0;
    for (int i = 0; i < N; i++){
        if (S.at(i) == 'I') x++;
        else x--;
        x_fin = max(x, x_fin);
    }
    cout << x_fin << endl;
}

Measured memory_bytes: 256
results = []

while True:
    str_in = input()
    if str_in == '-':
        break
    trial = int(input())

    for i in range(trial):
        h = int(input())
        str_in = str_in[h:] + str_in[:h]

    results.append(str_in)

for result in results:
    print(result)

Measured memory_bytes: 7496
import java.util.*; 
import java.io.*;

public class Main {
    static StringTokenizer st;
    static BufferedReader br;  
    static PrintWriter out;
 
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));

        int X = nextInt();
        
        if(X<600) System.out.println(8);
        else if(X<800) System.out.println(7);
        else if(X<1000) System.out.println(6);
        else if(X<1200) System.out.println(5);
        else if(X<1400) System.out.println(4);
        else if(X<1600) System.out.println(3);
        else if(X<1800) System.out.println(2);
        else  System.out.println(1);

    }
    
      
    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine().trim());
        return st.nextToken();
    }
}

Measured memory_bytes: 32776
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;

ll N;
ll A[100010];
std::map<ll, ll> mp;
ll ans;

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i], ++mp[A[i]];

  ll cnt = 0;

  for( auto it = mp.begin(); it != mp.end(); ++it )
  {
    ll add = std::max( it->second-1, 0ll );

    if( it->second > 0 )
      ++ans;

    cnt += add;
  }

  if( cnt&1 )
    cnt = 1;
  else
    cnt = 0;

  std::cout << ans-cnt << std::endl;

  return 0;
}

Measured memory_bytes: 7296
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;

int main() {
	long double ans,x;
	int n, i, j;
	string u;

	cin >> n;

	ans = 0;
	rep(i, n) {
		cin >> x >> u;
		if (u == "JPY")
			ans += x;
		else
			ans += x * 380000;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
dp = [float('inf') for i in range(N)]
#全ノードを取り敢えずinfにしておく
dp[0] = 0
for i in range(N-1):
    #足場を一個飛んだ時
    dp[i+1] = min(dp[i+1],dp[i] + abs(H[i+1] - H[i]))
    #足場を二個飛んだ時
    if i <= N-3:
        dp[i+2] = min(dp[i+2], dp[i] + abs(H[i + 2]-H[i]))
print(dp[N-1])

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

int main() {
	int N,M,X,Y;
	cin >> N >>M>>X>>Y;
	int x = X;
	for (int n = 0;n<N;++n) {
		int num;
		cin >> num;
		x = max(x, num);
	}
	int y = Y;
	for (int m = 0;m<M;++m) {
		int num;
		cin >> num;
		y = min(y, num);
	}
	if (x>=y) {
		cout << "War"<<endl;
	}
	else {
		cout << "No War" << endl;
	}
	return 0;
}

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



int main() {
  int N,D;
  cin>>N>>D;
  vector<vector<int>> X(N,vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin>>X.at(i).at(j);
    }
  }

  double sqsum=0.0;
  int count=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(i!=j&&i<j){
      for(int m=0;m<D;m++){
            sqsum+=(X.at(i).at(m)-X.at(j).at(m))*(X.at(i).at(m)-X.at(j).at(m));
      }
      double sq=sqrt(sqsum);
      if(ceil(sq) == floor(sq))count++;
      sqsum=0;
     }
   }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
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; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n, m;
int a[1010], b[1010];
int c[1010][12];
int bit[1010];
int dp[101010];
int main(){
    cin >> n >> m;
    REP(i, m){
        cin >> a[i] >> b[i];
        REP(j, b[i])cin >> c[i][j];
        REP(j, b[i])bit[i] += (1 << (c[i][j] - 1));
    }
    REP(i, 101010)dp[i] = HINF<int>();
    dp[0] = 0;
    REP(i, (1 << n)){
        REP(j, m){
            dp[i | bit[j]] = min(dp[i] + a[j], dp[i | bit[j]]);
        }
    }
    cout << (dp[(1 << n) - 1] == HINF<int>() ? -1 : dp[(1 << n) - 1]) << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr int MOD = 998244353;

int N, M, s, t;
double dp[606];

int main() {
  cin >> N >> M;
  vector<vector<int>> g(N);
  REP(i, M) {
    cin >> s >> t;
    --s, --t;
    g[s].push_back(t);
  }

  for(int i = N-2; i >= 0; --i) {
    double s = 0;
    for(int v : g[i]) s += dp[v];
    dp[i] = s / g[i].size() + 1;
  }

  double ans = dp[0];
  for(int i = 0; i < N-1; ++i) {
    if(g[i].size() == 1) continue;
    int cut = g[i][0];
    for(int nv : g[i]) if(dp[cut] < dp[nv]) cut = nv;

    // recalculate expectation value without cut
    vector<double> dp2(N);
    for(int j = N-2; j >= 0; --j) {
      double s = 0;
      for(int v : g[j]) {
        if(j == i && v == cut) continue;
        s += dp2[v];
      }
      dp2[j] = s / (g[j].size() - (j == i)) + 1;
    }
    ans = min(ans, dp2[0]);
  }
  cout << fixed << setprecision(10) << ans;
  return 0;
}

Measured memory_bytes: 1408
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,m; cin >> n >> m;
    ll sum = 0;
    rep(i,m){
        ll a; cin >> a;
        n -= a;
    }
    cout << (n < 0 ? -1 : n) << endl;
}

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

const long INF = 1L << 59;
const long MOD = 10 ^^ 9 + 7;


void main() {
    auto N = readln.chomp.to!int;
    auto edges = new Tuple!(int, long)[][](N);
    foreach (i; 0..N-1) {
        auto s = readln.split.map!(to!int);
        edges[s[0] - 1] ~= tuple(s[1] - 1, s[2].to!long);
        edges[s[1] - 1] ~= tuple(s[0] - 1, s[2].to!long);
    }
    auto dist = new long[](N);

    void dfs(int n, int p, long c) {
        dist[n] = c;
        foreach (m; edges[n]) if (m[0] != p) dfs(m[0], n, c + m[1]);
    }

    auto s = readln.split.map!(to!int);
    auto Q = s[0];
    auto K = s[1] - 1;
    dfs(K, -1, 0);
    while (Q--) {
        s = readln.split.map!(to!int);
        writeln(dist[s[0] - 1] + dist[s[1] - 1]);
    }
}


Measured memory_bytes: 30972
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define fs first
#define sc second

int main(void){
    ll n,k,q;
    cin >> n >> k >> q;
    vector<ll> point(n,k-q);
    ll a;
    rep(_,q){
        cin >> a;
        point[a-1]++;
    }
    rep(i,n){
        if(point[i] <= 0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }
}

Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int ret = 0;

void dfs(int i, vector<vector<int> > a, set<int> visited) {
    if (visited.size() == a.size()) {
        ret++;
    }
    else {
        for(auto ax : a[i]) {
            set<int> temp_v = visited;
            if(temp_v.count(ax) == 0) {
                temp_v.insert(ax);
                dfs(ax, a, temp_v);
            }
        }
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<int> > a(N);
    for(int i = 0; i < M; ++i) {
        int x, y;
        cin >> x >> y;
        a[x-1].push_back(y-1);
        a[y-1].push_back(x-1);
    }
    set<int> visited;
    visited.insert(0);
    dfs(0, a, visited);
    cout << ret << endl;
    return 0;
}

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

A = [0]*n
B = [0]*n
for i in range(n):
    A[i], B[i] = map(int,input().split())

A.sort()
B.sort()

#print(A)
#print(B)

if n%2:
    a = A[(n+1)//2-1]
    b = B[(n+1)//2-1]
    print(int(b-a+1))
else:
    a = (A[n//2-1]+A[n//2])/2
    b = (B[n//2-1]+B[n//2])/2
    print(int((b-a)*2+1))


Measured memory_bytes: 82172
fun main(args: Array<String>) {
    val ab = readLine()!!.split(" ").map { it.toLong() }
    val a = ab[0]
    val b = ab[1]
    val setA = mutableSetOf<Long>()
    val setB = mutableSetOf<Long>()
    for (i in 1..a) {
        if (a % i == 0L) {
            setA.add(i)
            setA.add(a/i)
        }
        if (i * i > a) break
    }
    for (i in 1..b) {
        if (b % i == 0L) {
            setB.add(i)
            setB.add(b/i)
        }
        if (i * i > b) break
    }
    setA.retainAll(setB)
    println(setA.count { setA.count { x -> it % x == 0L && it > x } <= 1 })
}



Measured memory_bytes: 41924
#include<iostream>
using namespace std;
int main(){
  
  int a=0,b=0;
  string s;
  cin>>s;
  for(int i=0; i<s.length(); i++){
  	if(s[i] == 'A') a++;
    else b++;
  }
  
  if(a==0 || b==0) cout<<"No\n";
  else cout<<"Yes\n";
return 0;
}

Measured memory_bytes: 256
n[M];main(i,j){n[0]=n[1]=1;for(i=2;i<M;i++)if(!n[i])for(j=i*2;j<M;j+=i)n[j]=1;for(;scanf("%d",&i),i;printf("%d %d\n",i-2,i))for(;n[i-2]||n[i];i--);return 0;}

Measured memory_bytes: 0
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int n;
  cin >> n;
  n++;
  vi a(n);
  rep(i, n) a[i] = i;
  for(int i=0;i<n;i+=3){
    a[i] = 0;
  }
  for(int i=0;i<n;i+=5){
    a[i] = 0;
  }

  ll ans = 0;
  rep(i, n){
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7160
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n) ; i++)
#define repp(i, n) for(int i = 1; i < (n) ; i++)
typedef long long ll;

int main()
{
    ll X, Y, ans, a, b, c;
    cin >> X >> Y;

    if ((X + Y) % 3 != 0) {
        ans = 0;
        cout << ans << endl;
        return 0;
    }

    ll quot;
    quot = (X + Y) / 3;

    if ((quot > X) || (quot > Y)) {
        ans = 0;
        cout << ans << endl;
        return 0;
    }

    a = X - quot;
    b = Y - quot;
    c = a > b ? b : a;

    if (c == 0) {
        ans = 1;
        cout << ans << endl;
        return 0;
    }


    /*quotCcを求める*/
    ll m = 1, n = 1, l = 1;
    rep(i, c) {
        m *= (quot - i);
        n *= (i+1);
        m %= 1000000007;
        n %= 1000000007;
     }
    
    while ((n * l) % 1000000007 != 1) {
        l++;
    }

    ans = (m * l) % 1000000007;

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

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
int N,M,Q;
vector <int> g[100004];
int col[100004],turns[100004];
bool vis[100004];
void bfs(int v,int d,int c){
	memset (vis,0,sizeof(vis));
	queue <pii> q;
	q.push(pii(v,0));
	while (!q.empty()){
		int x=q.front().first,dist=q.front().second;
		q.pop();
		if (d-dist<=turns[x]) continue;
		turns[x]=d-dist; 
		if (dist>d) continue;
		if (vis[x]) continue;
		vis[x]=1;
		if (col[x]==0) col[x]=c;
		for (int i=0;i<g[x].size();i++)
			q.push(pii(g[x][i],dist+1)); 
	}
}
int v[100004],d[100004],c[100004];
int main(){
	memset (col,0,sizeof(col));
	memset (turns,-1,sizeof(turns));
	cin>>N>>M;
	for (int i=0;i<M;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	cin>>Q;
	for (int i=0;i<Q;i++){
		cin>>v[i]>>d[i]>>c[i];
	}
	for (int i=Q-1;i>=0;i--)
		bfs(v[i],d[i],c[i]);
	for (int i=1;i<=N;i++)
		cout<<col[i]<<endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repf(i, f, l) for(int i = f; i < (int)l; ++i)
#define repit(it, t) for(__typeof((t).begin()) it = (t).begin(); it != (t).end(); it++)
#define endl "\n"
#define pb emplace_back
#define lb lower_bound
#define int long long
#define ul unsigned long
#define ull unsigned long long
#define ll long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second
#define DBG0(x) { cout << #x << ": " << x << "\t"; }
#define DBG(x) {DBG0(x); cout << endl;}
#define DBG2(x, y) {DBG0(x); DBG(y);}
#define DBG3(x, y, z) {DBG0(x); DBG2(y, z);}
#define DBG4(w, x, y, z) {DBG0(w); DBG3(x, y, z);}

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef vector<bool> vbl;
typedef pair<int, int> pii;

int ans[101][101];

signed main(void){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) rep(j, n) ans[i][j] = 0;
    if (n % 2 == 0) {
        repf(i, 2, n) {
            ans[1][i] = 1;
            ans[n][i] = 1;
        }
        repf(i, 2, n) {
            repf(j, i + 1, n) {
                if (j + i != n + 1) ans[i][j] = 1;
            }
        }
    } else {
        repf(i, 1, n) {
            ans[n][i] = 1;
        }
        repf(i, 1, n) {
            repf(j, i + 1, n) {
                if (j + i != n) {
                    ans[i][j] = 1;
                }
            }
        }
    }
    vector<pii> anss;
    repf(i, 1, n + 1) {
        repf(j, i, n + 1) {
            if (ans[j][i] == 1) ans[i][j] = 1;
        }
    }
    repf(i, 1, n + 1) {
        repf(j, i, n + 1) {
            if (ans[i][j] == 1) anss.push_back(pii(i, j));
        }
    }
    cout << anss.size() << endl;
    rep(i, anss.size()) cout << anss[i].fs << " " << anss[i].sd << endl;
    return 0;
}


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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long ll;
int a[1000003];
int b[1000003];
int z[1000003];
int cnt;
int bb;
void fj(int x)
{  // cout<<x<<"::: ";
   for(int i=2;i*i<=x;i++)
   {
       if(x%i==0)
       {
           if(b[i]>=1)bb=1,b[i]++;
           else {
            z[++cnt]=i;
            b[i]=1;
           }
         //  cout<<i<<" "<<b[i]<<endl;
       }
       while(x%i==0)
       {
           x/=i;
       }
   }
   if(x>1)
   {
       if(b[x]>=1)
       {
           bb=1;
           b[x]++;
       }else 
       b[x]=1;
   }
}

int main()
{
  /*  string s,s1;
    cin>>s>>s1;
    int Max=0;
    int len=s.size();
    int len1=s1.size();
    for(int
    cout<<len1-Max;*/
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
   for(int i=n;i>=1;i--)
     fj(a[i]);
     int Max=0;
     for(int i=1;i<=cnt;i++)
        Max=max(Max,b[z[i]]);
       // cout<<b[3];
     if(bb==0)cout<<"pairwise coprime\n";
     else if(Max!=n)cout<<"setwise coprime\n";
     else cout<<"not coprime\n";
}


Measured memory_bytes: 11376
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

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

int x[51];
int y[51];
int n;
void solve() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  map<pii, int> dp;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++) {
      if(i == j) continue;
      dp[{x[i] - x[j], y[i] - y[j]}]++;
    }
  }
  int ret = n;
  for(auto out: dp) {
    ret = min(ret, n - out.second);
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 384
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N];
        for(int n = 0; n < N; n++) {
            A[n] = sc.nextInt();
        }
        for(int n = 0; n < N; n++) {
            B[n] = sc.nextInt();
        }
        for(int n = 0; n < N-1; n++) {
            C[n] = sc.nextInt();
        }

        int X = 0;
        int Y = A[0];
        X = X + B[Y-1];

        for (int i = 1; i < N; i++) {
            Y = A[i]-1;
            if (A[i] - A[i-1] == 1) {
                X = X + B[Y] + C[Y-1];
            }
            else {
                X = X + B[Y];
            }
        }
        System.out.println(X);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1000010;
int x,n,fl,ans;
char s[maxn],t[maxn];
queue<int>q;
signed main()
{
    cin>>n>>s+1>>t+1;
    for(int i=1;i<=n;i++)if(s[i]!=t[i]){fl=1;continue;}
    if(!fl)puts("0"),exit(0);
    int x=n,y=n;
    while(y)
    {
        while(y>1&&t[y]==t[y-1])y--;
        while(x>0&&(x>y||s[x]!=t[y]))x--;
        if(x<=0)puts("-1"),exit(0);
        while (!q.empty()&&q.front()-q.size()>=y)q.pop();
        if(x!=y)q.push(x);
        ans=max(ans,(int)q.size()+1);
        y--;
    }
    cout<<ans;
}

Measured memory_bytes: 13412
#include <cstdio>
#include <cstdlib>
//#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <queue>
#include <set>
using namespace std;

#define MAXNUM 1000000

int main(void){

	bool nonPrimeMap[MAXNUM] = { false };
	nonPrimeMap[0] = true;
	nonPrimeMap[1] = true;

	for (int i = 2; i < MAXNUM; i++){
		if (nonPrimeMap[i])	continue;

		for (int j = 2; i * j < MAXNUM; j++){
			nonPrimeMap[i * j] = true;
		}
	}

	int a, d, n;
	while (cin >> a >> d >> n, a, d, n){
		int count = 0;
		int result;
		for (int k = 0; count < n;k++){
			if (!nonPrimeMap[a + k * d]){
				count++;
				result = a + k * d;
			}
		}

		cout << result << endl;
	}

	return 0;
}

Measured memory_bytes: 2144
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Solution solver = new Solution();
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solver.solve(1, in, out);
        out.close();
    }

    private static class Solution {
        static int INF = (int) 1e8;
        int[][] mem;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            mem = new int[m][(1 << (n + 1)) + 9];
            for (int[] x : mem) Arrays.fill(x, -1);
            int[] cost = new int[m];
            int[] keyMask = new int[m];
            for (int i = 0; i < m; ++i) {
                cost[i] = in.nextInt();
                int keys = in.nextInt();
                int mask = 0;
                for (int j = 0; j < keys; ++j) {
                    int box = in.nextInt() - 1;
                    mask |= (1 << box);
                }
                keyMask[i] = mask;
            }
            int res = solve(0, 0, n, cost, keyMask);
            if (res >= INF) {
                out.println("-1");
            } else {
                out.println(res);
            }
        }

        private int solve(int idx, int mask, int n, int[] cost, int[] keyMask) {
            if (allOnes(mask, n)) {
                return 0;
            }
            if (idx >= cost.length) return INF;
            if (mem[idx][mask] != -1) return mem[idx][mask];
            int res = solve(idx + 1, mask, n, cost, keyMask);
            res = Math.min(res, cost[idx] + solve(idx + 1, mask | keyMask[idx], n, cost, keyMask));
            mem[idx][mask] = res;
            return res;
        }

        private boolean allOnes(int mask, int n) {
            for (int i = 0; i < n; ++i) {
                if ((mask & (1 << i)) == 0) return false;
            }
            return true;
        }


    }

    private static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 23434);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

}


Measured memory_bytes: 79188
import java.util.Scanner;

public class Main {

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

		if(sc.nextInt() < sc.nextInt())
		{
			System.out.println(0);
		}
		else
		{
			System.out.println(10);
		}

		sc.close();
	}

}

Measured memory_bytes: 21460
#include<iostream>

using namespace std;

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(b - a <= 0){
        cout << "delicious" << endl;
    }else if (b - a <= x){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
    
}

Measured memory_bytes: 256
import itertools
moji = str(input())
A,B,C,D = int(moji[0]),int(moji[1]),int(moji[2]),int(moji[3])

Bn = [B,B*-1]
Cn = [C,C*-1]
Dn = [D,D*-1]
flg = 0
for i,j,k in itertools.product(Bn, Cn,Dn):
    X = A + i + j + k
    if X == 7:
        break
    
print(str(A) + (str(i),"+"+str(i))[i >= 0]+ (str(j),"+"+str(j))[j >= 0]+ (str(k),"+"+str(k))[k >= 0]+"=7")    


Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>
#include <stack>
#include <map>
#include <ctype.h>

using namespace std;

#define loop(i,n) for (i = 0; i < n; ++i) 
#define loop2(i,k,n) for (i = k; i <= n; ++i) 
#define loopb(i,k,n) for (i = k; i >= n; --i)
#define remove_space(x) x.erase(remove(x.begin(), x.end(), ' '), x.end())
typedef long long ll;

int main(){
    
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;

    if(s == "SUN"){
    	cout << 7;
    }

    if(s == "MON"){
    	cout << 6;
    }

    if(s == "TUE"){
    	cout << 5;
    }

    if(s == "WED"){
    	cout << 4;
    }

    if(s == "THU"){
    	cout << 3;
    }

    if(s == "FRI"){
    	cout << 2;
    }

    if(s == "SAT"){
    	cout << 1;
    }
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int m[6][4] = {{5,1,2,4},{1,3,1,0},{0,2,3,2},{2,4,5,1},{4,0,4,3},{3,5,0,5}};
int main(){
	for(int a,b,c,n,r,d;a=c=0,b=r=scanf("%d",&n),n;printf("%d\n",r)){
		for(char s[10];n--;r+=a%3?b%3?(b+6-a)%6<3?2:5:b?3:4:a?6:1){
			scanf("%s",s);
			d=-1;
			if(s[0]=='L')c+=3; 
			if(s[0]=='R')c++;
			if(s[0]=='W')d=1;
			if(s[0]=='N')d=0;
			if(s[0]=='E')d=3;
			if(s[0]=='S')d=2;
			if(d!=-1)
				a=m[a][(d+c)%4],
				b=m[b][(d+c)%4];
		}
	}
}

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

using namespace std;


int main()
{
    
    long int x;
    cin>>x;
    long long int i,j;
    int flag=0;
    for(i=0;i<=sqrt(x);++i)
      {
          for(j=-sqrt(x);j<=sqrt(x);++j)
            {
                if(pow(i,5)-pow(j,5)==x)
                  {
                      flag=1;
                      break;
                  }
            }
            
            if(flag==1)
               break;
      }
      
      cout<<i<<" "<<j;
       
    
     
     return 0;   
    
}

Measured memory_bytes: 4136
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int H, W;
    cin >> H >> W;

    vector<vector<int>> cells(H, vector<int>(W));
    REP(h, H) {
        REP(w, W) {
            cin >> cells[h][w];
        }
    }

    vector<pair<int,int>> odd_xys;
    REP(h, H) {
        if (h % 2 == 0) {
            REP(w, W) {
                if (cells[h][w] % 2) odd_xys.pb({w, h});
            }
        }
        else {
            for(int w = W-1; w >= 0; --w) {
                if (cells[h][w] % 2) odd_xys.pb({w, h});
            }
        }
    }

    vector<pair<pair<int,int>,pair<int,int>>> commands;
    auto size = SIZE(odd_xys);
    REP(i, size) {
        if (i != size - 1) {
            // i番目のコインを、i+1(=j)番目に移動させる
            auto& coin_i = odd_xys[i];
            const auto coin_j = odd_xys[i+1];
            // ジグザグ状にコインを移動させることで、
            // かならず同じマスを二度と選択しないように保証できる
            while (coin_i != coin_j) {
                pair<int, int> coin_next;

                // まず横方向の移動を試みる
                int direction = (coin_i.second % 2 == 0) ? 1 : -1;
                int next_x = coin_i.first + direction;
                // 盤面からはみ出る場合は下に移動
                if (next_x == -1 || next_x == W) {
                    coin_next = mp(coin_i.first, coin_i.second + 1);
                }
                // はみ出ない場合は横に移動
                else {
                    coin_next = mp(coin_i.first + direction, coin_i.second);
                }
                commands.pb({ coin_i, coin_next });
                coin_i = coin_next;
            }
            ++i;
        }
    }

    cout << SIZE(commands) << endl;
    for(auto com: commands) {
        cout << (com.first.second + 1) << " "
             << (com.first.first + 1) << " "
             << (com.second.second + 1) << " "
             << (com.second.first + 1) << endl;
    }
    return 0;
}


Measured memory_bytes: 7156
A,B,M=list(map(int, input().split()))
a=list(map(int, input().split()))
b=list(map(int, input().split()))
mi=min(a)+min(b)
for i in range(0,M):
  Data=list(map(int, input().split()))
  wari=a[Data[0]-1]+b[Data[1]-1]-Data[2]
  if(mi>wari):
    mi=wari
print(mi)

Measured memory_bytes: 18736
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <random>

using namespace std;

int main(){
  long long  k,a,b;
  cin >> k >> a >> b;
  if(b-a<=2){
    cout << (1+k)<< endl;
    return 0;
  }
  long long exc = k-a+1;
  if(exc<2){
    cout << (1+k)<<endl;
    return 0;
  }
  long long ans = a;
  ans += ((b-a) * (exc / 2)) + (exc & 1LL);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int selectionSort(int *,int);

int main(){
  int *akira;
  int i,count,n;

  scanf("%d",&n);
  akira=(int *)malloc(sizeof(int)*n);

  for(i=0;i<n;i++){
    scanf("%d",&akira[i]);
  }
  
  count=selectionSort(akira,n);
  
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",akira[i]);
  }
  printf("\n%d\n",count);
  
  return 0;
}
int selectionSort(int *akira,int n){
  int i,j,tmp,minj,count=0;

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++){
      if(akira[j]<akira[minj]) minj=j;
    }
    if(minj!=i){
      count++;
      tmp=akira[i];
      akira[i]=akira[minj];
      akira[minj]=tmp;
    }
  }
  return count;
}



Measured memory_bytes: 2104
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int a[200];

signed main()
{
	cin >> N;
	REP(i, N)
	{
		cin >> a[i];
	}

	ARY_SORT(a, N);

	int n = 0;
	int m = 0;
	for (int i = 0; i < N; i++)
	{
		if (i % 2 == 0)
		{
			n += a[N - i - 1];
		}
		else
		{
			m += a[N - i - 1];
		}
	}

	cout << n - m << endl;
}








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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

class UnionFind{
public:
  vector<int> Parents;

  UnionFind(int N){
    Parents.assign(N, -1);
  }

  int root(int A){
    if(Parents[A] < 0) return A;
    return Parents[A] = root(Parents[A]);
  }

  int size(int A){
    return -Parents[root(A)];
  }

  bool connect(int A, int B){
    A = root(A);
    B = root(B);

    if(A == B) return false;

    if(size(A) < size(B)) swap (A, B);

    Parents[A] += Parents[B];
    Parents[B] = A;
    return true;
  }
};





int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N, M;
    cin >> N >> M;

    vector<int> revp(N);
    for(int i = 0; i < N; i++){
        int p; cin >> p; p--;
        revp[p] = i;
    }

    UnionFind uf(N);
    for(int i = 0; i < M; i++){
        int x, y; cin >> x >> y;
        x--; y--;
        uf.connect(x, y);
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        int pos = revp[i];
        if(uf.root(pos) == uf.root(i)) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

#define X first
#define Y second

typedef pair<int, int> Pii;
  
int main() {
  int w, h, n;
  vector<Pii> p;
  
  cin >> w >> h >> n;
  
  for(int i=0; i<n; i++) {
    int x, y;
    cin >> x >> y;
    p.push_back(make_pair(x, y));
  }
    
  int res = 0;
  int const N = p.size();
  for(int i=0; i<N-1; i++) {
    int ww = p[i].X-p[i+1].X;
    int hh = p[i].Y-p[i+1].Y;
    if(ww*hh > 0) res += min(abs(ww), abs(hh)) + abs(abs(ww)-abs(hh));
    else res += abs(ww) + abs(hh);
  }
    
  cout << res << endl;
    
  return 0;
}

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

int main(){
	int k, a, b;
	scanf("%d%d%d", &k, &a, &b);
	for(int i = a; i <= b; i++) {
		if(i % k == 0) {
			printf("OK\n");
			return 0;
		}
	}
	printf("NG\n");
}


Measured memory_bytes: 3764
#include<stdio.h>
#include<stdlib.h>
#define INF 2100000000
#define LARGE 100000

typedef struct node{
	int cost;
	int flg;
}node;

typedef struct list{
	int id;
	int cost;
	struct list *next;
}list;


node N[LARGE];
list *L[LARGE];
int n;


void Make_AdjList(list* L[],int s,int t,int d){
	list *new=malloc(sizeof(list));
	list **p=&L[s];
	/*card作成*/
	new->id=t;	new->cost=d;  new->next=NULL;
	
	while((*p)!=NULL)p=&((*p)->next);
	(*p)=new;
	
	return;
}


void dfs(int start,int cnt){
	int u=start;
	list *p=L[u];
	
	if(cnt==n)return;
	
	while(p!=NULL){
		if(N[p->id].flg==0){
			N[p->id].cost=N[u].cost+p->cost;
			N[p->id].flg=1;
			cnt++;
			dfs(p->id,cnt);
		}
		p=p->next;
	}
	
	return;
	
}


int main(){
	int i,max,idx;
	int s,t,w;

	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		N[i].cost=INF;
		N[i].flg=0;
		L[i]=NULL;
	}
	
	while(scanf("%d %d %d",&s,&t,&w)!=EOF){
		if(s==-1)break;
		Make_AdjList(L,s,t,w);
		Make_AdjList(L,t,s,w);
	}
	
	
	N[0].cost=0;
	N[0].flg=1;
	dfs(0,1);
	
	max=-1;
	for(i=0;i<n;i++){
		if(N[i].cost!=INF){
			if(max < N[i].cost){
				max=N[i].cost;
				idx=i;
			}
		}
	}
	
	for(i=0;i<n;i++){
		N[i].cost=INF;
		N[i].flg=0;
	}
	
	N[idx].cost=0;
	N[idx].flg=1;
	
	dfs(idx,1);
	max=-1;
	for(i=0;i<n;i++){
		if(N[i].cost!=INF){
			if(max < N[i].cost){
				max=N[i].cost;
				idx=i;
			}
		}
	}
	
	printf("%d\n",max);
	
	return 0;
}


Measured memory_bytes: 12640