akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let mut buf = String::new();
    let handle = std::io::stdin();
    let info: Vec<isize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp
    };
    let n = info[0];
    let k = info[1];
    let hs: Vec<isize> = {
        handle.read_line(&mut buf).unwrap();
        let tmp = buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp
    };
    let mut memo: Vec<isize> = vec![-1; n as usize];
    println!("{}", dp(n, n, k, &hs, &mut memo));
}

fn dp(i: isize, n: isize, k: isize, hs: &Vec<isize>, memo: &mut Vec<isize>) -> isize {
    if i <= 1 { 
        memo[(i-1) as usize] = 0;
        return 0; 
    }
    if memo[(i-1) as usize] == -1 {
        let mut mini = std::isize::MAX;
        for j in 1..k+1 {
            if i > j {
                let h_2 = dp(i-j, n, k, hs, memo) + (hs[(i-1) as usize] - hs[(i-j-1) as usize]).abs(); 
                mini = std::cmp::min(mini, h_2);
            }
        }
        memo[(i-1) as usize] = mini;
    }
    memo[(i-1) as usize]
}


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


int main() {
  string s;
  cin >> s;
  int res = 0;
  int face = 0;
  int mask = 1;
  bool cond = false;
  for (int i = 0; i < s.size(); i++){
    if (s[i] == 'R') {

        mask |= 1 << face;

      face++;
    }
    else face--;
    face &= 3;
    if (face == 0){
      //cout << cond << " " << mask << endl;
      if (mask == 15) res++;
      cond = false;
      mask = 0;
    }
  }
  cout << res << endl;
}



Measured memory_bytes: 3204
//https://codeforces.com/contest/988/problem/A
//BROWNIE TK

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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod2 1000000007
#define mod 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/

int main()
{
    kira;
    lli n,m;
    cin>>n>>m;
    lli a[n];
    lli sum=0;
    forz(i,n)
    {
        cin>>a[i];
        sum+=a[i];
    }
    lli cnt=0;
    forz(i,n)
    {
        if((a[i]*4ll*m)>=sum)cnt++;
    }
    if(cnt>=m)p1("Yes");
    else p1("No");
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    string hi = "";
    for (int i = 0; i < 5; i++) {
        hi += "hi";
        if (hi == s) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 100005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int h, n;
ll dp[20010], a[10005], b[10005];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    cin>>h>>n;
    for(int i = 0; i < 20010; i++)
        dp[i] = infLL;
    for(int i = 0; i < n; i++)
        cin>>a[i]>>b[i];
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        for(int j = a[i]; j < 20010; j++)
        {
            dp[j] = min(dp[j-a[i]]+b[i], dp[j]);
        }
    }
    ll ans = infLL;
    for(int i = h; i < 20010; i++)
        ans = min(ans, dp[i]);
    cout<<ans<<endl;

    //End();
    return 0;
}


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

const int MAX_L = 8000;
int dp[MAX_L+1];
string s;

int main(){
    int x, y; cin >> s >> x >> y;

    vector<int> xx, yy;
    int cnt = 0, tmp = 0, sx = 0, sy = 0;

    for(auto c : s){
        if(c=='F') tmp++;
        else{
            if(cnt%2){
                yy.push_back(tmp); sy += tmp;
            }
            else{
                xx.push_back(tmp); sx += tmp;
            }
            tmp = 0; cnt++;
        }
    }

    if(tmp != 0){
        if(cnt % 2){
            yy.push_back(tmp); sy += tmp;
        }
        else{
            xx.push_back(tmp); sx += tmp;
        }
    }

    x -= xx[0]; sx -= xx[0];

    dp[0] = 1;
    for(int i=1;i<xx.size();i++){
        for(int j=1;j<=sx;j++){
            if(!dp[j] && xx[i]<=j) dp[j] = dp[j-xx[i]];
        }
    }

    if(abs(sx) < abs(x) || abs(sx%2) != abs(x%2) || !dp[(sx+x)/2]){
        cout << "No" << endl;
        return 0;
    }

    for(int i=1;i<=sy;i++) dp[i] = 0;
    for(int i=0;i<yy.size();i++){
        for(int j=1;j<=sy;j++){
            if(!dp[j] && yy[i]<=j) dp[j] = dp[j-yy[i]];
        }
    }

    if(abs(sy) < abs(y) || abs(sy%2) != abs(y%2) || !dp[(sy+y)/2]) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    l = input()
    n = len(l)

    dp_small = [0] * n
    dp_indet = [0] * n

    dp_small[0] = 1
    dp_indet[0] = 2

    for i in range(1,n):
        bit = l[i]

        if bit == "1":
            dp_small[i] += dp_small[i-1] * 3 + dp_indet[i-1]
            dp_indet[i] += 2 * dp_indet[i-1]
        else:
            dp_small[i] += dp_small[i-1] * 3
            dp_indet[i] += dp_indet[i-1]

        dp_small[i] %= MOD
        dp_indet[i] %= MOD

    print((dp_small[-1]+dp_indet[-1])% MOD)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41200
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main()
{
  int n;
  vector<vector<int>> a(3, vector<int>(3));
  REP(i, 3)REP(j, 3) cin >> a[i][j];
  cin >> n;
  vector<int> b(n);
  REP(i, n){
    cin >> b[i];
    REP(j, 3)REP(k, 3)if (a[j][k] == b[i]) a[j][k] = 0;
  }
  REP(i,3){
  if(a[0][i]==0&&a[1][i]==0&&a[2][i]==0){
    cout << "Yes";
    return 0;
  }else if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0){
    cout << "Yes";
    return 0;
  }
  }
  if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0){
    cout << "Yes";
    return 0;
  }else if(a[2][0]==0&&a[1][1]==0&&a[0][2]==0){
    cout << "Yes";
    return 0;
  }
  cout << "No";
  }
 

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1000+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

char s[maxn];
int dis[maxn][maxn],n,m;

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

int main() {
    read(n),read(m);
    memset(dis,63,sizeof dis);
    for(int i=1;i<=n;i++) {
        scanf("%s",s+1);
        for(int j=1;j<=m;j++) if(s[j]=='#') dis[i][j]=0;
    }
    queue<pii > q;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) 
            if(!dis[i][j]) q.push(mp(i,j));
    while(!q.empty()) {
        int x=q.front().fr,y=q.front().sc;q.pop();
        if(x<1||y<1||x>n||y>m) continue;
        for(int i=0;i<4;i++)
            if(dis[x+dx[i]][y+dy[i]]>inf)
                dis[x+dx[i]][y+dy[i]]=dis[x][y]+1,q.push(mp(x+dx[i],y+dy[i]));
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++) ans=max(ans,dis[i][j]);
    write(ans);
    return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  // ios::sync_with_stdio(false);
  // cin.tie(0);
  int n;
  cin >> n;
  // vector<vector<int>> v(n, vector<int> (n-1));
  int v[1010][1010];
  rep(i, n) rep(j, n-1){
    cin >> v[i][j];
    v[i][j]--;
  }
  vector<int> index(n, 0);
  // int index[1010];

  for (int i = 1; i <= ((n-1) * n) / 2; i++) {
    vector<bool> battled(n, false);
    // bool battled[1010];
    // rep(j, 1010) battled[j] = false;
    // cout << "===" << endl;
    // cout << i << endl;
    bool flag = true;
    for (int j = 0; j < n; j++) {
      if(index[j] >= n-1) continue;
      int enemy = v[j][index[j]];
      if(index[j] >= n-1 || index[enemy] >= n-1) continue;
      if(v[enemy][index[enemy]] == j && !battled[j] && !battled[enemy]){
        flag = false;
        battled[j] = true;
        battled[enemy] = true;
        index[enemy]++;
        index[j]++;
      }
    }
    if(flag) break;

    flag = true;
    rep(j, n){
      if(index[j] < n-1) {
        flag = false;
        break;
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

}


Measured memory_bytes: 4224
#coding utf-8
n_prob, n_submission = (int(x) for x in input().split())
condition = [[0,0] for _ in range(n_prob)] # 左がクリア状況、右が失敗数
n_penalty = 0
n_ac = 0

for i in range(n_submission):
    tmp = input().split()
    prob_num = int(tmp[0])
    ac_wa = tmp[1]
    if ac_wa == 'AC' and condition[prob_num-1][0] == 0:
        n_penalty += condition[prob_num-1][1]
        n_ac += 1
        condition[prob_num-1][0] = 1
    elif ac_wa == 'WA':
            condition[prob_num-1][1] += 1

print(n_ac , n_penalty)

Measured memory_bytes: 14580
#include<cstdio>
int main()
{
	int A,B,C;
	while(scanf("%d %d %d",&A,&B,&C)!=EOF){
		if(A+B==C||C+B==A||A+C==B)	printf("Yes\n");
		else		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define N 100

int main()
{
  int i,j,n,k,d,A[N];

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      d = A[j];
      if(A[j]<A[j-1]){
	A[j] = A[j-1];
      A[j-1] = d;
      k++;
      }
    }
  }
    for(i=0;i<n-1;i++) printf("%d ",A[i]);
    printf("%d\n",A[n-1]);
    printf("%d\n",k);

    return 0;
}
  
    
      
      



Measured memory_bytes: 2104
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        if (x < a) {
            System.out.print(0);
        } else {
            System.out.print(10);
        }
    }
}

Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
    fastIO;
    ll n,a,b;
    cin>>n>>a>>b;
    ll val,ans,val1=inf,val2;
    val=b-a;
    if(val%2==0)
    {
        val1=min(val1,val/2);
    }
    val2=min(a-1,n-b)+1+((val-1)/2);
    ans=min(val2,val1);
    cout<<ans<<'\n';
}

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

int main()
{
    
    int n, m;
    
    cin >> n >> m;
    vector<vector<int>> G(n);
    vector<int> ans(n);
    for(int i=0;i<n;i++){
      ans[i] = -1;
    }
    for(int i=0;i<m;i++){
      int a, b;
      cin >> a >> b;
      G[a-1].push_back(b-1);
      G[b-1].push_back(a-1);
    }
    queue<int> que;
    que.push(0);
    
    while(!que.empty()){
      int v = que.front();
      que.pop();
      for(int nv : G[v]){
        if(ans[nv] != -1){
          continue;
        }
        ans[nv]=v+1;
        que.push(nv);
      }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++){
      cout<<ans[i]<<endl;
    }
  
}

Measured memory_bytes: 10100
#!/usr/bin/env python3
#ABC97 C

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

f = defaultdict(lambda : 0)
s = input()
k = I()
n = len(s)
for i in range(1,k+1):
    for j in range(n-i+1):
        f[s[j:j+i]] = 1
f = sorted(f.items())
print(f[k-1][0])


Measured memory_bytes: 41452
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	bool flag=true;
	int i=0;
	do{
		if(i%2==0)
		{
			if(c<=b)
			{
				cout<<"Yes\n";
				flag=false;
				break;
			}
			c=c-b;
		}
		else
		{
			if(a<=d)
			{
				cout<<"No\n";
				flag=false;
				break;
			}
			a=a-d;
		}
		i++;
	}while(a>0 && c>0);
	if(a>0 && flag)
	   cout<<"Yes\n";
	else if(c>0 &&flag)
	   cout<<"No\n";
}

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

using namespace std;

int main() {
    string S; int K; cin >> S >> K;

    int max_one = 0;
    while (S[max_one] == '1') max_one++;
    if (K <= max_one) cout << 1 << endl;
    else cout << S[max_one] - '0' << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int X, A, B;
    scanf("%d %d %d", &X, &A, &B);

    if (B <= A) {
        printf("delicious\n");
    } else if (B - A <= X) {
        printf("safe\n");
    } else {
        printf("dangerous\n");
    }
    return 0;
}

Measured memory_bytes: 128
s=input()
n=int(input())
to_a=[(ord("z")+1-ord(c))%26 for c in s]
is_a=[False for c in s]
for i in range(len(s)):
  if n>=to_a[i]:
    n-=to_a[i]
    is_a[i]=True
    to_a[i]=0
n%=26
for i in range(len(s)-1,-1,-1):
    if not is_a[i]:
        s=s[:i]+chr(ord(s[i])+n)+s[i+1:]
        n=0
        break
if n>0:
    s=s[:-1]+chr(ord("a")+n)
    is_a[-1]=False
for i in range(len(s)):
  if is_a[i]:
    print("a",end="")
  else:
    print(s[i],end="")

Measured memory_bytes: 6304
n = int(input())
c = input()

cnt_r = [0] * (n + 1)
for i in range(n):
    if c[i] == 'R':
        cnt_r[i + 1] = cnt_r[i] + 1
    else:
        cnt_r[i + 1] = cnt_r[i]

ans = n
for i in range(n + 1):
    right_r = cnt_r[n] - cnt_r[i]
    left_w = i - cnt_r[i]
    ans = min(ans, max(right_r, left_w))

print(ans)


Measured memory_bytes: 17244
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        //static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var Ai = Sarray();
            var mnum = Ai.Count(a => a < 0);
            var absAi = Ai.Select(a => Abs(a));
            var sum = absAi.Sum();
            if (mnum % 2 == 0)
            {
                WriteLine(sum);
                return;
            }
            WriteLine(sum - 2 * absAi.Min());
        }
    }
}

Measured memory_bytes: 31452
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

int main() {
  int x, point = 0;
  cin >> x;
  if (x / 500 > 0) {
    point += (1000 * (x / 500));
    x %= 500;
  }
  if (x / 5 > 0) point += (5 * (x / 5));
  cout << point << endl;
}


Measured memory_bytes: 3588
row = list(map(int, input().split()))
max_water= 0
max_sugar = 0
max_percent = 0

for w1 in range(int(row[5]/(row[0]*100))+1):
    for w2 in range(int((row[5]-w1*100*row[0])/(row[1]*100))+1):
        for s1 in range(int((row[5]-w1*100*row[0]-w2*row[1]*100)/row[2])+1):
            for s2 in range(int((row[5]-w1*100*row[0]-w2*row[1]*100-s1*row[2])/row[3])+1):
                water = w1*100*row[0]+w2*row[1]*100
                sugar = s1*row[2]+s2*row[3]
                if sugar + water != 0 and water != 0:
                    percent = 100*sugar/(water + sugar)
                    if max_percent < percent <= 100*row[4]/(100+row[4]):
                        max_water = water
                        max_sugar = sugar
                        max_percent = percent
if max_water == 0:
    if row[0]*100 <= row[5]:
        max_water = row[0]*100
    elif row[1]*100 <= row[5]:
        max_water = row[1]*100

print(max_water+max_sugar, max_sugar)


Measured memory_bytes: 3192
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int value = sc.nextInt();
        HashSet<String> hs = new HashSet<String>();
        for (int i = 0; i < value; i++) {
            hs.add(sc.next());
        }
        System.out.println(hs.size());
        
    }
}


Measured memory_bytes: 77224
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

vector<int> E[210000];
long long int val[210000] = {};

void func(int pos, int pre, long long int cost){
    cost += val[pos];
    val[pos] = cost;
    for(int to : E[pos]){
        if(to != pre){
            func(to, pos, cost);
        }
    }
}

int main(){
    int N, Q;
    cin >> N >> Q;
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        int p, x;
        cin >> p >> x;
        val[p] += x;
    }
    func(1, 0, 0);
    for(int i = 1; i < N; i++){
        cout << val[i] << " ";
    }
    cout << val[N] << endl;
    return 0;
}

Measured memory_bytes: 24448
ans=[]
while 1:
    s1=input().split('"')
    if s1==["."]: break
    s2=input().split('"')
    if len(s1)!=len(s2):
        ans.append("DIFFERENT")
        continue
    else:
        cnt=0
        flag=0
        for i in range(len(s1)):
            if s1[i]!=s2[i]:
                if i%2==0:
                    ans.append("DIFFERENT")
                    flag=1
                    break
                else:
                    cnt+=1
            else: pass
        if flag==1:
            continue
        else: pass
        if cnt==0:
            ans.append("IDENTICAL")
        elif cnt==1:
            ans.append("CLOSE")
        else: 
            ans.append("DIFFERENT")

for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 5592
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<queue>
#define mem(x) memset(x,0,sizeof(x)) 
#define sca(x) scanf("%d",&x)
#define scaa(x,y) scanf("%d%d",&x,&y)
#define inf 0x7f7f7f7f
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#pragma GCC optimize(2)
using namespace std;
const double pi=acos(-1); 
const double eps=1e-6;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<char,char> pcc;
const ll mod=998244353;
int a[1004];
int main()
{
	int n;
	cin>>n;
	int x=n%10;
	int y=n/10%10;
	int z=n/100;
	if(x==7||y==7||z==7)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 3592
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;

public class Main{
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            int count = 1;
            while((line = stdReader.readLine()) != null) {
                int input = Integer.parseInt(line);
                
                // 0?????\?????????????????????
                if(input == 0) {
                    break;
                }
                
                System.out.println("Case " + count + ": " + input);
                count++;
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
}

Measured memory_bytes: 32104
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){

    int n;
    cin >> n;
    vector<int> a(n);

    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    } 

    sort(a.begin(), a.end());
    int alice = 0, bob = 0;

    for(int i = n - 1; i >= 0; i -= 2){
        alice += a.at(i);
    }
    
    for(int i = n - 2; i >= 0; i -= 2){
        bob += a.at(i);
    }

    cout << alice - bob;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    sum += 2 * min(v[i], k - v[i]);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    double x1,y1,x2,y2,d;
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    d=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%.8lf\n",d);
    return 0;

}



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

int main()
{
    int N; cin>>N;
    vector<long long> x(N), y(N);
    for (int i=0; i<N; i++)
        cin>>x[i]>>y[i];

    //  https://img.atcoder.jp/wtf19-open/editorial.pdf
    long long c = 1LL<<60;
    
    //  x+y=cの直線上のランプのみを点灯させたとき
    //  (x-p,p)のランプが点灯しているか
    auto check = [&](long long p)
    {
        bool ret = false;
        for (int i=0; i<N; i++)
            if (!(~(c-x[i]-y[i]) & (p-y[i])))
                ret = !ret;
        return ret;
    };

    //  check(0) = true
    //  check(p) = false for p<0
    long long p = 0;
    for (int k=60; k>=0; k--)
        if (check(p+(1LL<<k)))
            p += 1LL<<k;
    cout<<c-p<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

ll euc_algo( ll a, ll b ){  //最大公約数を返す
  while( b != 0 ){
    a = a % b;
    swap( a, b );
  }
  return a;
}

bool IsPrime( ll n ){ //素数であればtrue
  for( ll i = 2; i < n; i++ ){
    if( n % i == 0 ){
      return false;
    }
  }
    return true;
}

int main(){
  ll A, B;
  cin >> A >> B;
  
  ll gcm = euc_algo( A, B ); // AとBの最大公約数
//  cout << "gcm=" << gcm << endl;

  
  ll ans = 0;  //gcmの素因数の数＋１が答えとなる
  set<ll> factors = {}; //このsetに素因数を格納する
  ll i = 2;   //素因数の候補
  while( gcm != 1 && i*i <= gcm ){
    if( gcm % i == 0 ){
      factors.insert( i );
      gcm /= i;
//      cout << " /" << i << endl;
      continue;
    }
    i++;
  }
  if( gcm != 1 ) factors.insert( gcm );
  ans = factors.size() + 1;
  
  cout << ans;
  return 0;
}
  


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

int main() {
	int f[8]={4,1,4,1,2,1,2,1},p[8],c[8],d[8],i,j,ln,n,m,s,a;
	while(cin >> c[0] >> c[1] >> c[2] >> c[3] >> c[4] >> c[5] >> c[6] >> c[7]) {
	m=0; ln=44444444;
	for (j=0;j<8;j++) p[j]=f[j];
	for (i=0;i<8;i++) {
		s=0; 
		for (j=0;j<8;j++) if (p[j]>=c[j]) s+=c[j]; else s+=p[j];
		if (s>=m) {
			n=0; a=1;
            for (j=7; j>=0; j--) {n+=p[j]*a; a*=10;}
			if (m==s) { if (n<ln) { ln=n; for (j=0;j<8;j++) d[j]=p[j];} }
			else  { ln=n; m=s; for (j=0;j<8;j++) d[j]=p[j]; }
		}
    a=p[7];
	for (j=6;j>=0;j--) p[j+1]=p[j];
	p[0]=a;
	}
    for (j=0; j<7; j++) cout << d[j] << ' ';
	cout << d[7] << endl;
	}
return 0;
}

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

int main(void){
    int n,k;
    cin >> n >> k;
    int a[n],num = 0;
    for(int i = 0;i < n;i++)cin >> a[i];
    for(int i = 0;i < n;i++)if(a[i] == 1)num = i + 1;
    
    int ans = n;
    for(int i = 0;i < k;i++){
        int sum = 0;
        for(int j = 1;j < num+i;j += (k-1))sum++;
        for(int j = num+i;j < n;j += (k-1))sum++;
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	static int n;//頂点数
	static boolean[][] side;//辺があるかどうか
	static int[] visit;//訪問済みかどうか
	static int[] d;
	static Queue <Integer> q;
	static int dis=0;
	static void bfs() {
		while(! q.isEmpty()) {
			int x=q.remove();
			dis=d[x]+1;
			for(int i=1; i<=n; i++) {
				if(visit[i]!=1 && side[x][i]) {
					visit[i]=1;
					d[i]=dis;
					q.add(i);
				}
			}
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			n=sc.nextInt();
			side=new boolean[n+1][n+1];
			d=new int[n+1];
			visit=new int[n+1];
			q=new LinkedList<>();
			for(int i=0; i<n; i++) {
				int u=sc.nextInt();
				int k=sc.nextInt();
				for(int j=0; j<k; j++) {
					int v=sc.nextInt();
					side[u][v]=true;
				}
			}
			visit[1]=1;
			q.add(1);
			bfs();
			for(int i=2; i<=n; i++) {
				if(d[i]==0) {
					d[i]=-1;
				}
			}
			for(int i=1; i<=n; i++) {
				System.out.printf("%d %d\n", i, d[i]);
			}

		}
	}
}


Measured memory_bytes: 29284
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int A;
int arr[8];
int main(){
  int Lj4PdHRW, add=0, res=0;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
    rd(A);
    A /= 400;
    if(A < 8){
      arr[A] = 1;
    }
    else{
      add++;
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(8==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = arr[0];
      for(KL2GvlyY=(1);KL2GvlyY<(8);KL2GvlyY++){
        Q5VJL1cS += arr[KL2GvlyY];
      }
    }
    res =Q5VJL1cS;
  }
  if(res==0){
    res++;
    add--;
  }
  wt_L(res);
  wt_L(' ');
  wt_L(res+add);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// int N, A, arr[8];
// {
//   int res = 0, add = 0;
//   rd(N);
//   rep(N){
//     rd(A);
//     A /= 400;
//     if(A < 8) arr[A] = 1;
//     else      add++;
//   }
// 
//   res = sum(arr(8));
//   if(res==0) res++, add--;
//   wt(res,res+add);
// }


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

using namespace std;

const int N = 200;
int n,m,r;
int dis[N][N] = {0};
int dp[N][N] = {0};
int cit[N];


int main() {
	cin >> n >> m >> r;
	for(int i = 0; i < r; i++) cin >> cit[i];
	for(int i = 0; i < r; i++) cit[i]--;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			dp[i][j] = 1e9;
	for(int i = 0; i < n; i++) dp[i][i] = 0;
	for(int i = 0; i < m; i++) {
		int x,y,z;
		cin >> x >> y >> z;
		x--;y--;
		dp[x][y] = z;
		dp[y][x] = z;
	}
	for(int k = 0; k < n; k++) 
		for(int i = 0; i < n; i++) 
			for(int j = 0; j < n; j++) 
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
	sort(cit,cit+r);
	int res = 1e9;
	do {
		int tmp = 0;
		for(int i = 1; i < r; i++) tmp += dp[cit[i-1]][cit[i]];
		if(res > tmp) res = tmp;
	} while (next_permutation(cit,cit+r));
	cout << res << endl;
	
	return 0;
}




Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;


int main(void) {
    ll c[3][3];
    ll i, j;
    ll s[3];
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++)
            cin >> c[i][j];
    }
    
    for(j=0; j<3; j++) {
        for(i=0; i<3; i++) {
            s[i]=c[i][(j+1)%3]-c[i][j];
        }
        
        if(s[0]==s[1] && s[1]==s[2]) continue;
        puts("No");
        return 0;
    }
    
    for(i=0; i<3; i++) {
        for(j=0; j<3; j++) {
            s[j]=c[(i+1)%3][j]-c[i][j];
        }
        
        if(s[0]==s[1] && s[1]==s[2]) continue;
        puts("No");
        return 0;
    }
    
    puts("Yes");
}



Measured memory_bytes: 256
stan = 10**9+7
def pow(x):
    start = 1
    for i in range(1,x+1 ):
        start = start * i % stan
    return start
n,m = [int(x) for x in input().split(' ')]
n, m = max([n,m]), min([n,m])
if n - m > 1:
    print(0)
    exit()
if n - m == 1:
    sum = pow(n) * pow(m)
    print(sum % stan)
elif n == m:
    sum = pow(n) * pow(m)
    print(2 * sum % stan)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
#define ff first
#define se second
#define MAX 1000001
#define MAXN 200001
#define mod 1000000007 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    if(n%2==0){
        if(k<=n/2){
            cout<<"YES";
        }
        else{
            cout<<"NO";
        }
    }
    else{
        if(k<=(1+n/2)){
            cout<<"YES";
        }
        else{
            cout<<"NO";
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=100010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int k;
char s[maxn];
std::vector<int> v1,v2;
ll sum1[maxn];
ll sum2[maxn];
int main()
{
    //freopen("D:\\common_text\\code_stream\\in.txt","r",stdin);
	//freopen("D:\\common_text\\code_stream\\out.txt","w",stdout);
	gbtb;
	cin>>n>>k;
	cin>>s;
	int cnt=0;
//	int i=0;
    if(s[0]=='0')
    {
        v1.pb(0);
    }
	repd(i,0,n-1)
	{
	    if(s[i]=='0')
        {
            while(s[i]=='0')
            {
                cnt++;
                i++;
            }
            v2.push_back(cnt);
            cnt=0;
            i--;
        }
        if(s[i]=='1')
        {
            while(s[i]=='1')
            {
                cnt++;
                i++;
            }
            v1.push_back(cnt);
            cnt=0;
            i--;
        }

	}
	int num=max(sz(v1),sz(v2));
	repd(i,1,maxn-2)
	{
	    v1.push_back(0);
	    v2.push_back(0);
	}
	repd(i,1,maxn-2)
	{
		sum1[i]+=sum1[i-1]+v1[i-1];
		sum2[i]+=sum2[i-1]+v2[i-1];
	}
	int w=0;
	ll ans=0ll;
	repd(i,1,n-k+4)
	{
		int l=i;
		int r=l+k;
		ll temp=sum1[r]-sum1[l-1];
		temp+=sum2[r-1]-sum2[l-1];
		ans=max(ans,temp);
	}
	cout<<ans<<endl;



    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 3308
fun main(args: Array<String>) {
    val (n, a, b) = readLine()?.split(" ")?.map(String::toLong) ?: return
    val m = 1000000007L

    val nc = mPow(2, n, m) - 1
    val minus = (mCnr(n, a, m) + mCnr(n, b, m)) % m
    println((nc - minus + m) % m)
}

fun mCnr(n: Long, r: Long, m: Long): Long {
    val nc = (n - r + 1).until(n + 1).fold(1L) { a, b ->
        (a * (b)) % m
    }
    val rc = 0.until(r).fold(1L) { a, b ->
        (a * (r - b)) % m
    }
    return (nc * mPow(rc, m - 2, m)) % m
}

fun mPow(n: Long, ex: Long, m: Long): Long {
    var x = n
    var remain = ex
    var result = 1L
    while (remain > 0) {
        if (remain % 2L == 1L) {
            result = (result * x) % m
        }
        x = (x * x) % m
        remain /= 2
    }
    return result
}


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

int main() {
  int N;
  cin >> N;
  long sum=0;
  long a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
    sum+=a[i];
  }
  long s=a[0];
  long min=10000000000;
  for(int i=1;i<N-1;i++){
    s+=a[i];
    if(min>abs(sum-2*s))min=abs(sum-2*s);
  }
  if(N==2)min=abs(a[0]-a[1]);
  cout << min;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
typedef long long ll;
#define rep(i,a,b) for(ll i =a ;i <= b;i++)
#define per(i,a,b) for(ll i =a ;i >= b;i--)
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;




int main()
{
	//ifstream cin("input.txt");
	ll n,k;
	cin>>n>>k;
	ll hi = k;
	int count = 1;
	while(n >= hi)
	{
		hi *=k;
		count ++;
	}
	cout<<count;
}

Measured memory_bytes: 3576
#include<vector>
#include<queue>
#include<iostream>
using namespace std;

#define INF 2000000000

class max_flow {
private:
	struct edge { int to, cap, rev; };
	int v;
	vector<vector<edge>>G;
	vector<int>itr, level;
public:
	max_flow(int v) :v(v) { G.assign(v, vector<edge>()); }

	void add_edge(int from, int to, int cap) {
		G[from].push_back(edge { to, cap, (int)G[to].size() });
		G[to].push_back(edge { from, 0, (int)G[from].size() - 1 });
	}

	void bfs(int s) {
		level.assign(v, -1);
		queue<int>q;
		level[s] = 0; q.push(s);
		while (!q.empty()) {
			int v = q.front(); q.pop();
			for (auto &e : G[v]) {
				if (e.cap > 0 && level[e.to] < 0) {
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}

	int dfs(int v, int t, int f) {
		if (v == t)return f;
		for (int& i = itr[v]; i < (int)G[v].size(); ++i) {
			edge& e = G[v][i];
			if (e.cap > 0 && level[v] < level[e.to]) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int run(int s, int t) {
		int ret = 0, f;
		while (bfs(s), level[t] >= 0) {
			itr.assign(v, 0);
			while ((f = dfs(s, t, INF)) > 0)ret += f;
		}
		return ret;
	}
};

int gcd(int a, int b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}

int main() {
	int m,n;
	while (1) {
		cin >> m >> n;
		if (m == 0)break;
		max_flow max_flow(m + n + 2);
		vector<int>b, r;
		for (int i = 0; i < m; i++) {
			int buf;
			cin >> buf;
			b.push_back(buf);
		}
		for (int i = 0; i < n; i++) {
			int buf;
			cin >> buf;
			r.push_back(buf);
		}
		for (int i = 0; i < m; i++) {
			max_flow.add_edge(m + n, i, 1);
			for (int j = 0; j < n; j++) {
				if (gcd(b[i], r[j]) != 1)max_flow.add_edge(i, m + j, 1);
				if (i == 0)max_flow.add_edge(m + j, m + n + 1, 1);
			}
		}
		int ans = max_flow.run(m + n, m + n + 1);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 7320
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll solve(ll N){
    return 0;
}

int main(){
    ll X,Y; cin >> X >> Y;
    ll ans = 0;
    if(X == 1 && Y == 1) ans += 400000;
    if(X == 1) ans += 300000;
    if(Y == 1) ans += 300000;
    if(X == 2) ans += 200000;
    if(Y == 2) ans += 200000;
    if(X == 3) ans += 100000;
    if(Y == 3) ans += 100000;
    pr(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T,class U>
ostream& operator << (ostream& os,pair<T,U>& p){
	os << p.fi << ',' << p.sec; return os;
}
template<class T,class U>
istream& operator >> (istream& is,pair<T,U>& p){
	is >> p.fi >> p.sec; return is;
}
template<class T>
ostream& operator << (ostream &os,const vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		os << vec[i];
		if(i+1<vec.size())os << ' ';
	}
	return os;
}
template<class T>
istream& operator >> (istream &is,vector<T>& vec){
	for(int i=0;i<vec.size();i++)is >> vec[i];
	return is;
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
int N;
struct block{
  int w,s;
  ll v;
  block(){}
  block(int w,int s,ll v):w(w),s(s),v(v){}
  bool operator < (const block& a) const {
    return w+s < a.w+a.s;
  }
};
block bs[1010];
ll dp[1010][20010];
int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> bs[i].w >> bs[i].s >> bs[i].v;
  }
  sort(bs,bs+N);
  for(int i=0;i<=N;i++){
    for(int j=0;j<=10000;j++){
      dp[i][j] = -LLINF;
    }
  }
  dp[0][0] = 0ll;
  for(int i=0;i<N;i++){
    for(int j=0;j<=10000;j++){
      if(dp[i][j]==-LLINF)continue;
      chmax(dp[i+1][j],dp[i][j]);
      if(bs[i].s>=j)chmax(dp[i+1][j+bs[i].w],dp[i][j]+bs[i].v);
    }
  }
  ll ans = -LLINF;
  for(int i=0;i<=N;i++){
    for(int j=0;j<=20000;j++){
      if(dp[i][j]==-LLINF)continue;
      chmax(ans,dp[i][j]);
    }
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 156928
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int n, ans;
string s, t;

void calc(int p, int cnt){
  if(ans <= cnt) return;
  if(p == n){
    ans = min(ans, cnt);
    return;
  }
  if(s[p] == t[p]){
    calc(p+1, cnt);
    return;
  }
  int d = t[p] - s[p];
  for(int i=p;i<n;i++){
    for(int j=p;j<=i;j++) s[j] = ((s[j] - '0') + d + 10) % 10 + '0';
    calc(p+1, cnt+1);
    for(int j=p;j<=i;j++) s[j] = ((s[j] - '0') - d + 10) % 10 + '0';
  }
}

main(){
  while(cin >> n && n){
    cin >> s >> t;
    ans = n;
    calc(0, 0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 1200
package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

var sc = newScanner()

type proc struct {
	name      string
	time, fin int
}

func main() {
	n, q := scanInt(), scanInt()
	queue := list.New()
	f := make([]*proc, 0, n)
	for i := 0; i < n; i++ {
		p := &proc{scanString(), scanInt(), 0}
		queue.PushBack(p)
	}

	total := 0
	for queue.Len() > 0 {
		e := queue.Front()
		queue.Remove(e)
		p := e.Value.(*proc)
		if p.time > q {
			total += q
		} else {
			total += p.time
		}
		p.time -= q
		if p.time <= 0 {
			p.fin = total
			f = append(f, p)
		} else {
			queue.PushBack(p)
		}
	}
	for i := 0; i < n; i++ {
		fmt.Println(f[i].name, f[i].fin)
	}
}



Measured memory_bytes: 9532
#include <stdio.h>

int main(void){
    int w, h, x, y, r;
    scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);
    
    if(x+r>w || x-r<0 || y+r>h || y-r<0){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}



Measured memory_bytes: 2104
a = list(input().split())
n = len(a)
s = []
for i in a:
    if i=="+":
        a = s.pop()
        b = s.pop()
        s.append(b + a)
    elif i=="-":
        a = s.pop()
        b = s.pop()
        s.append(b - a)
    elif i=="*":
        a = s.pop()
        b = s.pop()
        s.append(b * a)
    else:
        s.append(int(i))
print(s[0])

Measured memory_bytes: 7544
import std.stdio,std.math,std.string,std.conv,std.typecons,std.format;
import std.algorithm,std.range,std.array;

T[] readarr(T=long)(){return readln.chomp.split.to!(T[]);}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}

//END OF TEMPLATE

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

Measured memory_bytes: 256