akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        total = 0
        for s in range(m):
            for k in range(m):
                if a[i+s][j+k] == b[s][k]:
                    total += 1
        if total == m*m:
            print("Yes")
            exit()
print("No")

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

using namespace std;

int n, a, b;

int main() {
	cin >> n >> a >> b;
	int diff = b - a - 1;
	if (diff % 2 == 1) cout << "Alice";
	else cout << "Borys";
	cout << endl;
	
	return 0;
}


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

#define MIN(X,Y) ((Y) < (X) ? (Y) : (X))

#define DMAX (1000 * (1 + 5 + 10 + 50 + 100 + 500))
#define NMAX 5

static int p;
static int d[NMAX + 1];
static const int w[NMAX + 1] = {1, 5, 10, 50, 100, 500};

static int pmin;
static int pmax;

static int uid[DMAX + 1];
static int pid[DMAX + 1];

static void
genuid()
{
  int i, j;
  pmin = p;
  pmax = 0;
  for (i = 0; i <= NMAX; ++i) {
    pmax += w[i] * d[i];
  }
  for (i = pmin; i <= pmax; ++i) {
    int val = i;
    uid[i] = 0;
    for (j = NMAX; j >= 0; --j) {
      uid[i] += MIN(val / w[j], d[j]);
      val -= w[j] * MIN(val / w[j], d[j]);
    }
    if (val != 0) {
      uid[i] = -1;
    }
  }
}

static void
genpid()
{
  int i, j;
  for (i = 0; i <= DMAX; ++i) {
    int val = i;
    pid[i] = 0;
    for (j = NMAX; j >= 0; --j) {
      pid[i] += val / w[j];
      val %= w[j];
    }
  }
}

main()
{
  int i;
  
  genpid();
  for (;;) {
    int res;
    
    scanf("%d", &p);
    for (i = 0; i <= NMAX; ++i)
      scanf("%d", &d[i]);
    if (p == 0) break ;
    genuid();

    res = 6000;
    for (i = pmin; i <= pmax; ++i) {
      if (uid[i] < 0) continue ;
      res = MIN(res, uid[i] + pid[i - p]);
    }
    printf("%d\n", res);
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 5760
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
ans = []
a = N
b = 1
if N % 2 == 1:
    while a != b and M > 0:
        ans.append((a, b))
        a -= 1
        b += 1
        M -= 1
else:
    a = N
    b = 1
    for i in range(((N-2)//2+1)//2):
        if M == 0:
            break
        ans.append((a, b))
        a -= 1
        b += 1
        M -= 1
    a -= 1
    for i in range(((N-2)//2)//2):
        if M == 0:
            break
        ans.append((a, b))
        a -= 1
        b += 1
        M -= 1
for a, b in ans:
    print(a, b)

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

int main(void){
	int s,i;
  	char str[100],*p,*q;
  
  	fgets(str,sizeof(str),stdin);
  	p=strtok(str," \n");
  	q=strtok(NULL," \n");
  	sprintf(str,"%s%s",p,q);
  	s=atoi(str);
  
  	for(i=1;i<1000;i++){
      if(i*i==s){
        printf("Yes\n");
        break;
      }else if(i*i>s){
        printf("No\n");
        break;
      }
    }
  	if(i==1000){
      printf("No\n");
    }
  	
  
  return 0;

}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

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

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

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

  int n, k; std::cin >> n >> k;
  vi l(n); rep(i, n) std::cin >> l[i];
  sort(l.rbegin(), l.rend());
  int sum = 0;
  rep(i, k) sum += l[i];
  std::cout << sum << "\n";
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define MOD 1000000007

int mod13[100000][10];
ll dp[100001][13] = {1};

void calc(int num, int i) {
    REP(j, 13) {
        int next = (j + mod13[i][num]) % 13;
        dp[i + 1][next] = (dp[i + 1][next] + dp[i][j]) % MOD;
    }
}

int main() {
    REP(i, 10) mod13[0][i] = i;
    FOR(i, 1, 100000) REP(j, 10) mod13[i][j] = (mod13[i - 1][j] * 10) % 13;

    string S;
    cin >> S;
    reverse(ALL(S));
    REP(i, S.size()) {
        if (S[i] == '?') {
            REP(j, 10) calc(j, i);
        }
        else {
            calc(S[i] - '0', i);
        }
    }
    cout << dp[S.size()][5] << endl;
    return 0;
}

Measured memory_bytes: 14592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>

using namespace std;

int main(){
	int H,W,h,w;
	int ans;

	cin >> H >> W >> h >> w;

	ans = H*W - h*W - w*H + h*w;

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
s = gets.chomp.split(//)

ar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.split(//)

ans = s.map do |c|
  # p c
  i = ar.index(c)
  i = (i + n)%26
  ar[i]
end

puts ans.join('')

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

int main()
{
    int a[4],i;
    for(i=1;i<=3;i++)
    {
        cin>>a[i];
    }
    sort(a+1,a+4);
    if(a[3]-a[2]==a[2]-a[1])
    {
        cout<<"YES"<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    return 0;
}

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

using namespace std;

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

    int sum = 0;
    if (A > B) {
        sum += A;
        A--;
    } else {
        sum += B;
        B--;
    }
    if (A > B) {
        sum += A;
    } else {
        sum += B;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int k = 30000;
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		x--;
		p[x] = i;
	}
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		a[i] = b[n - 1 - i] = (i + 1) * k;
	}
	for (int i = 0; i < n; i++) {
		b[i] += p[i];
	}
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << a[i];
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		if (i > 0) cout << " ";
		cout << b[i];
	}
	cout << endl;
	return 0;
}

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

#include <unistd.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
 
 
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

signed main() {
  int x, y;
  cin >> x >> y;
  ll ans = 0;
  if (x <= 3) {
    ans += (4 - x) * 100000;
  }
  if (y <= 3) {
    ans += (4 - y) * 100000;
  }
  if (x == 1 and y == 1) {
    ans += 400000;
  }
  cout << ans << endl;
  
}


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

#define endl "\n"
#define int long long

const int MOD = 1e9 + 7;
const int INF = 2e15;

signed main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

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

	int n;
	cin >> n;

	vector <int> heights(n + 1, 0);
	for (int i = 1; i <= n; i++) cin >> heights[i];

	vector <int> dp(n + 1, INF);
	dp[0] = 0;
	dp[1] = 0;
	dp[2] = abs(heights[2] - heights[1]);

	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(heights[i] - heights[i - 1]), dp[i - 2] + abs(heights[i] - heights[i - 2]));
	}

	cout << dp[n] << endl;
}

Measured memory_bytes: 4788
let N = Int(readLine()!)!

let p = readLine()!.split(separator: " ").map { Double($0)! }

var dp: [[Double]] = .init(repeating: .init(repeating: 0, count: N+1), count: N+1)
dp[0][0] = 1.0
for i in 1...N {
  for j in 0...i {
    dp[i][j] = (j == 0) ? dp[i-1][0] * (1.0 - p[i-1]) : dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1.0 - p[i-1]) 
  }
}
var sum: Double = 0.0
for j in (N+1)/2...N {
  sum += dp[N][j]
}
print(sum)

Measured memory_bytes: 78464
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n = int(input())
c = 0
for i in range(4**9):
  cur = Base_10_to_n(i, 4)
  if '0' in cur:
    continue
  if cur.count('1') == 0 or cur.count('2') == 0 or cur.count('3') == 0:
    continue
  cur = cur.translate(str.maketrans('123', '357'))
  if int(cur) <= n:
    c += 1
print(c)

Measured memory_bytes: 3188
# Problem B - AcCepted

# input process
S = input()

# initialization
is_a_ok = False
is_s_ok = False
s_len = len(S)
count = 0

# count process
for i in range(s_len):
    if i==0 and S[i]=='A':
        is_a_ok = True
        count += 1
        continue

    if i+1>=3 and (i+1)<=(s_len-1):
        if S[i]=='C':
            is_s_ok = True
            count += 1
            continue

    if S[i].isupper():
        count += 1

if count==2 and is_a_ok and is_s_ok:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 3064
N, K = map(int ,input().split())
mod = 10**9+7
B = K
R = N-K

def nCk_mod(n,k,mod):
	if n < k:
		return 1
	out = 1
	for i in range(n-k+1,n+1):
		out *= i
		out %= mod
	for i in range(1,k+1):
		out *= pow(i,mod-2,mod)
		out %= mod

	return out

ans = []

for i in range(1,B+1):
	if R < i-1:
		ans.append(0)
		continue
	s_1 = nCk_mod(B-1,i-1,mod)
	s_2 = nCk_mod(R+1, i, mod)

	ans.append((s_1*s_2)%mod)

for a in ans:
    print(a, end=" ")
print()

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

int main(int argc, char** argv) 
{
#ifdef HOME
	if(IsDebuggerPresent())
	{
		freopen("../in.txt", "rb", stdin);
		freopen("../out.txt", "wb", stdout);
	}
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout << fixed;
	int N, Q, B, C;
	cin >> N;
	vector<int> A(N);
	vector<int64_t> a(100003);
	int64_t su = 0;
	for (auto& ai : A)
	{
		cin >> ai;
		su += ai;
		a[ai]++;
	}

	cin >> Q;

	forn(qq, Q)
	{
		cin >> B >> C;
		int64_t db = a[B];
		su += (C - B) * db;
		a[B] = 0;
		a[C] += db;
		cout << su << endl;
	}

	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

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

        bool ok = false;
        rep2(i, 1, 10)
        {
                if (N % i == 0)
                {
                        int X = N / i;
                        if (1 <= X && X <= 9)
                        {
                                ok = true;
                        }
                }
        }
        if (ok)
        {
                puts("Yes");
        }
        else
        {
                puts("No");
        }
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> G[100005];
int Takahashi[100005];
int Aoki[100005];

void bfs(int* table, int st){
  queue<pair<int,int>> que;
  que.push(make_pair(st, 0));
  while(!que.empty()){
    pair<int,int> p = que.front(); que.pop();
    if(table[p.first] != -1) continue;
    table[p.first] = p.second;
    rep(i,G[p.first].size()){
      if(table[G[p.first][i]] == -1){
        que.push(make_pair(G[p.first][i], p.second + 1));
      }
    }
  }
}

int main(){
  int N;
  cin >> N;
  int u, v;
  cin >> u >> v;
  rep(i,N-1){
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  rep(i,100005){
    Takahashi[i] = -1;
    Aoki[i] = -1;
  }

  bfs(Takahashi, u);
  bfs(Aoki, v);

  int ret = 0;
  REP(i,1,N+1){
    if(Takahashi[i]<Aoki[i]){
      ret = max(ret, Aoki[i]);
    }
  }

  cout << ret - 1 << endl;
  
  return 0;
}



Measured memory_bytes: 6784
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val input = mutableMapOf<Int, List<Long>>()
    (1..n).forEachIndexed { index, i -> input[index] =  readLine()!!.split(' ').map(String::toLong)}
    val dp = Array(n) { LongArray(3) { 0L } }
    dp[0][0] = input[0]!![0]
    dp[0][1] = input[0]!![1]
    dp[0][2] = input[0]!![2]

    for (i in 1 until n) {
        dp[i][0] = Math.max(dp[i - 1][1], dp[i - 1][2]) + input[i]!![0]
        dp[i][1] = Math.max(dp[i - 1][0], dp[i - 1][2]) + input[i]!![1]
        dp[i][2] = Math.max(dp[i - 1][0], dp[i - 1][1]) + input[i]!![2]
    }
    println(dp[n-1].max())
}

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

int euclid(int x,int y){
	
	if(x%y==0) return y;
	else  return euclid(y,x%y);


}
int main(){
	int x,y;
	cin>>x;
	cin>>y;
	cout<<euclid(x,y)<<endl;


}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int mod = 1000000007;

struct Mod {
  int num;
  Mod () : num(0) {;}
  Mod (int n) : num(n) {;}
  operator int() { return num; }
};

Mod operator+(Mod a, Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator-(Mod a, Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator*(Mod a, Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator+=(Mod &a, Mod b) { return a = a + b; }
Mod operator-=(Mod &a, Mod b) { return a = a - b; }

int sp(const string &s, int i) {
  while(i < s.size() && s[i] == ' ') ++i;
  return i;
}

pair<Mod, int> num(const string &s, int i) {
  Mod val;
  Mod p10 = 1;
  while(i < s.size() && '0' <= s[i] && s[i] <= '9') {
    val += p10 * Mod(s[i] - '0');
    p10 = p10 * Mod(10);
    ++i;
  }
  return make_pair(val, i);
}

pair<Mod, int> expr(const string &s, int i);

pair<Mod, int> term(const string &s, int i) {
  if (s[i] == '>') {
    ++i;
    i = sp(s, i);
    Mod val;
    tie(val, i) = expr(s, i);
    i = sp(s, i);
    ++i;
    i = sp(s, i);
    ++i;
    return make_pair(val * val, i);
  } else {
    return num(s, i);
  }
}

pair<Mod, int> expr(const string &s, int i) {
  Mod val;
  tie(val, i) = term(s, i);
  i = sp(s, i);
  if (i < s.size() && s[i] == '>') {
    i += 2;
    i = sp(s, i);
    auto rhs = expr(s, i);
    //cout<<val<<' '<<rhs.first<<endl;
    if (val < 31)
      val = (int)rhs.first >> (int)val;
    else
      val = 0;
    i = rhs.second;
  }
  return make_pair(val, i);
}

int main() {
  while(1){
    string s;
    getline(cin,s);
    if(s[0]=='#')break;
    reverse(begin(s),end(s));
    cout << expr(s, 0).first << endl;
  }
  return 0;
}

Measured memory_bytes: 2872
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll HW_MAX = 300;
constexpr ll Q_MAX = 100000;

ll H, W, D;
ll A[HW_MAX][HW_MAX];
ll Q;
ll L[Q_MAX];
ll R[Q_MAX];

void input() {
	scanf("%lld%lld%lld", &H, &W, &D);
	rep(i, H) rep(j, W) scanf("%lld", &A[i][j]);
	scanf("%lld", &Q);
	//rep(i, Q) scanf("%lld%lld", L + i, R + i);
}


void solve() {
	vector<pair<ll,ll>> m(H*W+1);
	rep(i, H) rep(j, W) {
		m[A[i][j]]=make_pair(i,j);
	}
	debug(m);
	//ll rui[HW_MAX][H*W+1];
	vector<ll> rui(H*W+1,0);
	repeq(l,D){
		ll i=l;
		pair<ll,ll> p;
		p=m[l];
		ll count=0;
		while(true){
			debug(i);
			i+=D;
			if(i>H*W)break;
			auto q=m[i];
			count+=abs(p.first-q.first)+abs(p.second-q.second);
			rui[i]=count;
			p=q;
		}
	}
	debug(rui);
	while(Q--){
		ll l,r;
		scanf("%lld%lld", &l, &r);
		ll count=rui[r]-rui[l];
		p(count);
	}

}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 3968
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if(a <= c && c <= b){
				System.out.println("Yes");
			}
			else{
				System.out.println("No");
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, k;
	cin >> a >> b >> k;

	int lim = min(a, b);
	for (int i = lim; i >= 1; --i) {
		if (a%i == 0 && b%i == 0)
			--k;

		if (k == 0) {
			cout << i << endl;
			break;
		}
	}

	return 0;
}

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

using namespace std;

#define FASTIO ios_base::sync_with_stdio(false), cin.tie(NULL)
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl '\n'
#define mkp make_pair
#define trav(x, i) for(auto& i : x)

constexpr int INF =  1000000001;
constexpr int MOD =  1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;


int main() {
    FASTIO;
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3656
import itertools
l = []
for _ in range(5):
    l.append(int(input()))
k = int(input())
flag = 0
for ele in itertools.combinations(l, 2):
    if ele[1] - ele[0] > k:
        flag = 1
if flag == 0:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;
  vi L(N);
  cin >> L;
  sort(rall(L));
  int sum = 0;
  rep(i, 1, N) sum += L[i];
  out(L[0] < sum ? "Yes" : "No")
}


Measured memory_bytes: 256
import copy
N,M = map(int,input().split())
graph = [[] for _ in range(N)]
edges = []
for _ in range(M):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
    edges.append([a-1,b-1])


def dfs(G,v):
    seen[v] = True
    #print(seen)
    for nv in G[v]:
        #print(nv)
        if seen[nv]:
            continue
        dfs(G,nv)

ans = 0
for edge in edges:
    seen = [False] * N
    copied_graph = copy.deepcopy(graph)
    copied_graph[edge[0]].remove(edge[1])
    copied_graph[edge[1]].remove(edge[0])
    dfs(copied_graph,0)
    if not all(seen):
        ans += 1

print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
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;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++)
    {
        cin >> h[i];
    }

    const long long INF = 1LL << 60;
    const int LEN = 1000010;
    long long dp[LEN];
    for (int i = 0; i < LEN; i++)
    {
        dp[i] = INF;
    }
    dp[0] = 0;

    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
        {
            if (i - j >= 0)
            {
                chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            }
        }
    }
    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mkp                 make_pair
#define f(i,l,h)            for(ll i=l;i<h;i++)
#define fr(i,h,l)           for(ll i=h;i>=l;i--)
#define mem(a,val)          memset(a,val,sizeof(a))
#define all(v)              (v).begin(),(v).end()
#define ff                  first
#define ss                  second
#define spc(x)              cout<<fixed<<setprecision((x));
#define deb(x)              cout<<#x<<" "<<x<<endl;
#define deba(x)             cout<<#x<<": "; for(auto u:x) cout<<u<<" ";  cout<<endl;
#define check               cout<<"hello"<<endl;
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
const ld pi=3.141592653589793;
const ll mod=998244353;
const ll INF=(ll)(1e9+7);
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

ll power(ll a,ll b){
    ll res=1;
	while(b){
	    if(b&1) res=(res*a);
	    a=(a*a);
	    b>>=1;
	}
	return res;
}

int main()
{
    //cout << "Hello world!" << endl;
    ll n;
    cin>>n;
    ll a[n];
    f(i,0,n) cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll i=0;
    ll cnt=0;
    ll ans=a[i];
    i++;
    cnt+=2;
    while(cnt<n){
        ans+=a[i];
        cnt++;
        if(cnt<n){
            ans+=a[i];
            cnt++;
        }
        i++;
    }

    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 5204
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


x = inpl()
for i in range(5):
    if x[i] != i + 1:
        print(i + 1)
        break


Measured memory_bytes: 68880
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mxn=3e3+3;
ll n,m,md=1000000007,dp[mxn][mxn][2];
inline void add(ll&x,ll y){
	x+=y;
	if(x>=md)x-=md;
}
inline void solve(){
	cin>>n>>m;
	dp[0][0][1]=1;
	for(int i=1;i<=n;++i)dp[0][i][0]=1;
	for(int i=0;i<m;++i){
		for(int j=0;j<=n;++j){
			for(int k=0;k<2;++k){
				if(!dp[i][j][k])continue;
				if(j)add(dp[i+1][j-1][k|(j==1)],dp[i][j][k]),add(dp[i+1][j][k|(j==1)],dp[i][j][k]);
				if(n-j)add(dp[i+1][j][k],dp[i][j][k]),add(dp[i+1][j+1][k],dp[i][j][k]);
			}
		}
	}
	ll ans=0;
	for(int i=0;i<=n;++i)add(ans,dp[m][i][1]);
	cout<<ans<<'\n';
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;//cin>>T;
	for(;T--;)solve();
}


Measured memory_bytes: 144352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	vector<int>l(n);
	for(int i=0;i<n;i++)
		cin>>l[i];
	int cnt=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			for(int k=j+1;k<n;k++){
				int a=l[i],b=l[j],c=l[k];
				if(a==b||a==c||b==c)
					continue;
				if(a+b>c&&a+c>b&&b+c>a)
					cnt++;
			}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3604
#n = gets.chomp.to_i
de = false
n, C = gets.chomp.split().map(&:to_i)

d = []
C.times do
  d.push gets.chomp.split().map(&:to_i)
end
c = []
n.times do
  c.push gets.chomp.split().map(&:to_i)
end

g = Array.new(C+1){Array.new(3, 0)}

(1..C).each do |colori|
  n.times do |i|
    n.times do |j|
      g[colori][(i+j)%3] += d[c[i][j]-1][colori-1]
    end
  end
end

ans = Float::INFINITY
(1..C).each do |i|
  (1..C).each do |j|
    next if i == j
    (1..C).each do |k|
      next if k == i || k == j
      tmp = g[i][0] + g[j][1] + g[k][2]
      #p tmp
      ans = [ans, tmp].min
    end
  end
end

puts ans


Measured memory_bytes: 4476
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define pb         push_back
#define mp         make_pair
#define ll         long long
#define PI         acos(-1.0)
#define ALL(A)     ((A).begin(), (A).end())
#define vsort(v)   sort(v.begin(),v.end())
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

 
#define ll long long
#define MP make_pair

int main(void){
    ll int N, M;
    cin >> N >> M;
    ll int ans = 0;
    if(N*2<=M){
        ans = N;
        M -= ans*2;
        ans += M/4;
    }
    else{
        ans = M/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdio>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<ll,ll> P;
int n,x,ans;
bool a[105],b[105],c[105];
int main(void){
    cin>>n>>x;
    for(int i=0;i<x;i++){
        int y;
        cin>>y;
        a[--y]=true;
    }
    cin>>x;
    for(int i=0;i<x;i++){
        int y;
        cin>>y;
        b[--y]=true;
    }
    cin>>x;
    for(int i=0;i<x;i++){
        int y;
        cin>>y;
        c[--y]=true;
    }
    for(int i=0;i<n;i++){
        if((!a[i]&&c[i])||(b[i]&&c[i]))ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
 
int main() 
{
	int i;
	char c[6];
	for(i=0;i<6;i++){
		cin >> c[i];
	} 	
	cout << (c[0]==c[5] && c[1]==c[4] && c[2]==c[3] ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<vector>
#include<iomanip>
using namespace std;
typedef long long ll;
ll inf = 100000000;
ll v[205];
ll x[20000005];
ll a[10000005];
ll b[10000005];
ll dp[10005][10005];
ll ex = 1000000007;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
typedef pair<ll, ll> P;
double q[200005];
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}
string s[200005];
P p[100005];
int main() {
	string s;
	cin >> s;
	int count = 0;
	int kai = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '1') {
			count++;
		}

		else {
			kai++;
		}
	}
	cout << 2 * min(count, kai) << endl;
	return 0;
}





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

using namespace std;

vector<int> comps;
vector<int> sz;

void dfs(int v, vector<vector<int>> &g, int curr)
{
    comps[v] = curr;
    ++sz[curr];
    for(int i : g[v])
    {
        if (!comps[i])
        {
            dfs(i, g, curr);
        }
    }
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<vector<int>> g(n);
    for(int i = 0;i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    comps.assign(n, 0);
    sz.assign(n + 1, 0);
    vector<set<int>> d(n);
    for(int i = 0; i < k; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;
        d[a].insert(b);
        d[b].insert(a);
    }
    int cnt = 1;
    //cout << "OK" << endl;
    for(int i = 0;i < n; ++i)
    {
        if (!comps[i])
        {
            dfs(i, g, cnt++);
        }
    }
    --cnt;
    //cout << "OK" << endl;
    for(int i = 0;i < n; ++i)
    {
        int currans = sz[comps[i]] - g[i].size();
        for(auto j = d[i].begin(); j != d[i].end(); ++j)
        {
            if (comps[i] == comps[*j])
                --currans;
        }
        cout << currans - 1 << ' ';
    }
}

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

#define int long long
#define rep(i,n) for(int i=0;i<n;i++)

int N, Q;
vector<int> G[200010];
int ans[200010];

void DFS(int v, int p=0)
{
    if(p != 0)ans[v] += ans[p];
    for(auto u : G[v])if(u != p)DFS(u, v);
}

signed main()
{
    cin >> N >> Q;
    rep(i, N - 1)
    {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    rep(i, Q)
    {
        int p, x;
        cin >> p >> x;
        ans[p] += x;
    }

    DFS(1);

    for(int i = 1; i <= N; i++)
    {
        if(i - 1)cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

int main()
{
    ll N,W;
    cin >> N >> W;
    vector<ll> dp(W+1,0);

    for(int i=0;i<N;++i){
        ll w,v;
        cin >> w >> v;
        for(int j=W;j>=0;j--){
            if(j-w >=0)
                dp[j] = max(dp[j], dp[j-w] + v);
        }
    }

    ll maxi = 0;
    for(const auto& x : dp){
        maxi = max(maxi, x);
    }

    cout << maxi << '\n';


    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int a_500,b_100,c_50,X;
  cin >> a_500 >> b_100 >> c_50 >> X;
  int count=0;
  
  for(int i=0; i<=a_500; i++){
    for(int j=0; j<=b_100; j++){
      for(int k=0; k<=c_50; k++){
        if(500*i + 100*j + 50*k == X){
          count++;
        }
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
module Main (main) where
import Data.List.Split
import Control.Monad
import Control.Applicative
import Text.Printf
main :: IO ()
main = do
  n <- readLn
  replicateM_ n $ do
    ps <- getPoints
    let (x,y,z) = solve ps
    printf "%.3f %.3f %.3f\n" x y z


type Point = (Double,Double)

getPoints :: IO [Point]
getPoints = map mkPair . chunksOf 2 . map read . words <$> getLine
  where
    mkPair (x:y:_) = (x,y)


{-
(x - px)^2 + (y-py)^2 = (x-qx)^2 + (y - qy)^2
2(qx - px)x + 2(qy - py) = qx^2 + qy^2 - px^2 - py^2
2(rx - px)x + 2(ry - py) = rx^2 + ry^2 - px^2 - py^2
-}

subst (p,q) (r,s) = (p - r,q - s)

solve :: [(Double, Double)] -> (Double, Double, Double)
solve (p@(px,py):(qx,qy):(rx,ry):_) = (x,y,sqrt $ ax*ax + ay*ay)
  where
    (ax,ay) = subst p o
    o@(x,y) = solveEq a b c d e f
    a = 2 * (qx - px)
    b = 2 * (qy - py)
    c = qx*qx + qy*qy - px*px - py*py
    d = 2 * (rx - px)
    e = 2 * (ry - py)
    f = rx*rx + ry * ry - px*px - py*py


solveEq :: Double -> Double -> Double -> Double -> Double -> Double -> (Double, Double)
solveEq a b c d e f = (x,y)
  where
    x = (e * c - b * f) / (a * e - d * b)
    y = (a * f - d * c) / (a * e - d * b)

Measured memory_bytes: 4480
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextLong()

    val m = Math.pow(10.0, 9.0).toLong() + 7L

    var ans = 1L
    for (i in 1..n) {
        ans = (ans * i % m)
    }

    println(ans)
}


Measured memory_bytes: 31392
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, n) for (int i = (a); i < (n); ++i)
using namespace std;
using ll = long long;
using uint = unsigned int;
const ll mod = (ll)1e9 + 7;

int main() {
  int x;
  cin >> x;
  if (x >= 30)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3564
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	char buf[81];
	int sum = 0,tmp;

	while(scanf("%s",buf)!=EOF){
		tmp = 0;
		for(int i=0;buf[i] != '\0';i++){
			if(buf[i] >= 48 && buf[i] <= 57){
				tmp = 10*tmp + (buf[i] - '0');
				if(buf[i+1] == '\0'){
					sum += tmp;
				}
			}else{
				if(buf[i-1] >= 48 && buf[i-1] <= 57){
					sum += tmp;
					tmp = 0;
				}
			}
		}
	}

	printf("%d\n",sum);

    return 0;
}

Measured memory_bytes: 2588
//itp1_topic1_d
#include <bits/stdc++.h>
using namespace std; 
int main(){
    int x;
    cin>>x;

    // 整数どうしの割り算は小数点が切り捨てられます
    // X％60 で　Xを60で割ったあまりを計算できます
    int h = x/3600;
    int m =(x/60)%60;
    int s = x%60;
    cout<<h<< ":"<<m<<":"<<s<<endl;
  

    return 0;
}


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

/*

*/

int main(){
    
    string S, ans = "WA";
    cin >> S;
    
    if ( S[0] == 'A') {
        int cnt = 0;
        for ( int i = 2; i < S.size() - 1 ; i++ ) {
            if ( S[i] == 'C') cnt++;
        }
        if ( cnt == 1 ) {
            cnt = 0;
            for ( int i = 0; i < S.size(); i++ ) {
                if ( S[i] >= 'A' && S[i] <= 'Z') cnt++;
            }
            if ( cnt == 2) {
                ans = "AC";
            }
        }
    }
    cout << ans << endl;
    
}


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

int main(){
    int N; cin >> N;
    int ans = 101;
    for(int i = 0; i < N; i++){
        int N, cnt = 0; cin >> N;
        while(!(N%2)){
            N /= 2; cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

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

  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t res = (N / (A + B)) * A;
  if (N % (A+B) >= A) {
    res += A;
  } else {
    res += (N % (A+B));
  }
  cout << res << endl;

  return 0;
}


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

const int MAX = 500000;

class Z {
	private:
		vector<int> z;
	public:
		Z(string S);
		int get(int n);
};

Z::Z(string S) {
	int i = 1, j = 0, k, n = S.size();
	z.resize(n);
	z[0] = n; // 最初は当然だが全一致
	while(i < n) {
		while (i + j < n && S[j] == S[i + j]) ++ j; // 順に先頭一致か確認して進めていく
		z[i] = j; // とりあえず結果を入れる
		if (j == 0) { // j=0、つまり開幕から文字が違うならもう再利用できないので次のiは愚直
			++ i;
			continue;
		}
		k = 1;
		while (i + k < n && k + z[k] < j) { // 一致している文字列に対して再利用できるよ
			z[i + k] = z[k];
			++ k;
		}
		i += k; // 再利用した分も求まっているのでカット
		j -= k; // その個数だけ前の分は再利用できなくなってるので消しておく
	}
}

int Z::get(int n) {
	return z[n];
}

int main() {
	string w, w2;
	cin >> w;
	w2 = w;
	reverse(w2.begin(), w2.end());
	Z z1(w), z2(w2);
	
	int N = w.size();
	int ans = N;
	static bool G[MAX];
	for (int i = 0;i <= N;i ++) G[i] = true;
	for (int p = 1;p < N;p ++) {
		if (!G[p - 1]) continue;
		for (int k = 2;(k - 1) * p <= z1.get(p) && k * p <= N;k ++) {
			if (G[k * p - 1]) {
				-- ans;
				G[k * p - 1] = false;
			}
		}
		for (int k = 2;(k - 1) * p <= z2.get(p) && N - k * p - 1 > 0;k ++) {
			if (G[N - k * p - 1]) {
				-- ans;
				G[N - k * p - 1] = false;
			}
		}
	}
	
	if (G[N - 1]) cout << 1 << endl << 1;
	else if (ans <= 1) cout << N << endl << 1;
	else cout << 2 << endl << ans;
	
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

解説AC
答えの項数は1, 2, |w|の3種類しかない点に注意
1は単純にwが良い文字列の時
|w|は全て同じ文字の時
そうでないなら答えは常に2
ということは、1番目から|w|-1番目までのどこかに分割点があって両側が良い文字列であるということ
後は、良い文字列の判定をO(1)で行うとO(N)で解けるよ
*/

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

int main(){
  int n;
  cin >> n;
  for(int i=0; i<n; i++){
    int k,p;
    cin >> k >> p;
    if(k<p){
     cout << k << endl; 
    }else if(k%p == 0){
     cout << p << endl; 
    }else{
     cout <<  k%p <<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3092
//om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share 

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[2*100002],b[2*100002];
int main(){
    ll n,s=0;
    cin>>n;
    forn(i,n) {
        cin>>a[i];
        s^=a[i];
    }
    forn(i,n) cout<<(s^a[i])<<" ";
}

Measured memory_bytes: 5136
#include <stdio.h>
#include <string.h>

int main(int argc, char const *argv[]) {
    int count = 0;
    char W[10];
    scanf("%s", W);
    char T[1000];

    while (scanf("%s", T) && strcmp(T, "END_OF_TEXT") != 0 ) {    
        for (int i = 0; i < strlen(T); i++) {
            if ('A' <= T[i] && T[i] <= 'Z') {
                T[i] -= 'A' - 'a';
            }
        }
        if (strcmp(W, T) == 0) {
            count++;
        }
    }

    printf("%d\n", count);

    return 0;

}


Measured memory_bytes: 2044
#include <stdio.h>

int main(void) {
	int W,H,x,y,r,ans;
	
	
	scanf("%d",&W);
	scanf("%d",&H);
	scanf("%d",&x);
	scanf("%d",&y);
	scanf("%d",&r);
	
	if( 0 <=  W - (x + r) && W <=  W + (x - r) && 0 <= H - (y + r) && H <= H + (y - r) ){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 584
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		num := nextInt(sc)
		if num == 0 {
			break
		}

		score_list := []int{}
		for i := 0; i < num; i++ {
			score_list = append(score_list, nextInt(sc))
		}
		// 得点リストをソートした後、最低点と最高点を取り除く(3 ≤ n ≤ 100)
		sort.Sort(sort.IntSlice(score_list))
		score_list = score_list[1 : len(score_list)-1]
		// 得点リストの得点を合計し、スライスの個数で割って平均点を出す
		sum := 0
		for _, score := range score_list {
			sum += score
		}
		fmt.Println(sum / len(score_list))
	}
}


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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll s;
  vector<bool> a(1000000,false);
  cin >> s;
  ll count = 1;
  a[s] = true;
  while(true){
    if(s%2==0) s=s/2;
    else s=3*s+1;
    count++;
    if(a[s] == true) break;
    a[s] = true;
  }
  cout << count << endl;
}


Measured memory_bytes: 384
n = gets.to_i

arr = Array.new(n)
n.times do |i|
  arr[i] = gets.to_i
end
arr = arr.sort

m = n / 2
if n % 2 == 0
  sum = -2 * arr[0...(m - 1)].sum
  sum += 2 * arr[(m + 1)..-1].sum
  sum += arr[m] - arr[m - 1]
else
  sum = -2 * arr[0...(m - 1)].sum 
  sum += 2 * arr[(m + 2)..-1].sum 
  sum1 = sum + 2 * arr[m + 1] - arr[m] - arr[m - 1]
  sum2 = sum + arr[m + 1] + arr[m] - 2 * arr[m - 1]
  sum = [sum1, sum2].max
end
puts sum

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

int main()
{
  ll n; cin >> n;
  set<string> st;
  for (int i=0; i<n; i++){
    string s; cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;

  return 0;
}


Measured memory_bytes: 19204
# include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n;
char str[maxn];
int main(){
//	freopen("tmp.in","r",stdin);
	scanf("%d",&n);
	scanf("%s",str);
	int ans = 0,nowres = 0;
	for(int i=1;i<n;++i) nowres += str[i] == 'E'; ans=nowres;
	for(int i=1;i<n;++i){
		nowres = nowres - (str[i]=='E') + (str[i-1]=='W');
		ans=min(ans,nowres);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int d[101],e[101],t=0,n;
bool went[101],graph[101][101];
void dfs(int x){
    if(went[x])return;
    went[x]=true;
    t++;
    d[x]=t;
    for(int i=1;i<=n;i++){if(graph[x][i])dfs(i);}
    t++;
    e[x]=t;
    return;
}
int main(){
    int m,temp,a;
    scanf("%d",&n);
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++)graph[i][j]=false;
        went[i]=false;
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&a,&m);
        for(int j=0;j<m;j++){
            scanf("%d",&temp);
            graph[a][temp]=true;
        }
    }
    for(int i=1;i<=n;i++)dfs(i);
    for(int i=1;i<=n;i++)printf("%d %d %d\n",i,d[i],e[i]);
}

Measured memory_bytes: 2692
#include <cstdio>
int main(){
	int n;
	scanf("%d", &n);
	long long ans = 0;
	for (long long i = 1; i <= n; i++){
		if (i % 3 != 0 && i % 5 != 0) ans += i;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1708