akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}





int main()
{

	int n, k;
	cin >> n >> k;

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

	long long int maxi = 0;
	for (int i = 0; i < k; i++) {
		maxi += p[i];
	}
	
	long long int wk = maxi;

	for (int i = k; i < n; i++) {
		wk -= p[i - k];
		wk += p[i];

		maxi = max(maxi, wk);
	}

	maxi += k;

	double ans = (double)maxi / 2.0;

	printf("%.10lf\n", ans);





	return 0;



}



Measured memory_bytes: 1024
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))

m1 = 0
m2 = 0

for ind, i in enumerate(a):
    if i>m1:
        m2 = m1
        m1 = i
        m_i = ind
    elif i>m2:
        m2 = i

for i in range(n):
    if i==m_i:
        print(m2)
    else:
        print(m1)


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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> digit(N, INT_MAX);
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (digit[s - 1] != INT_MAX && c != digit[s - 1]) {
      cout << -1 << endl;
      return 0;
    }
    digit[s - 1] = c;
  }
  if (N != 1 && digit[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    if (digit[i] != INT_MAX) {
      continue;
    }
    if (N != 1 && i == 0) {
      digit[i] = 1;
    } else {
      digit[i] = 0;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << digit[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair

using namespace std;

int32_t main()
{
	ios::sync_with_stdio(false); cin.tie(NULL); cout.precision(10);
	int a; cin >> a;
	int b; cin >> b;
	int c; cin >> c;
	cout << a + b + c - max(a, max(b, c));
}

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

int main() {
    string s;
    cin >> s;
    
    vector<char> a;
    for(int i = 0; i < s.size(); i += 2){
        a.push_back(s[i]);
    }
    
    for(int i = 0; i < a.size(); i++){
        cout << a[i];
    }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define EPS 1e-9
#define MOD 1000000007
#define range 
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#pragma GCC optimize ("Ofast")
int main(){

 //   freopen("input.txt","r",stdin);
    IOS;
    clock_t clk = clock();
	int n;cin>>n;
	int a[n];
	forn(i,n)cin>>a[i];        

	sort(a, a+n);
	double curr = a[0];
	forn1(i,n-1){
		curr = curr + a[i];
		curr = curr/2;
	}
	cout<<curr<<endl;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');

var a = lines.filter(function(line){return line.split(',')[1] == 'A';}).length;
var b = lines.filter(function(line){return line.split(',')[1] == 'B';}).length;
var ab = lines.filter(function(line){return line.split(',')[1] == 'AB';}).length;
var o = lines.filter(function(line){return line.split(',')[1] == 'O';}).length;

console.log(a);
console.log(b);
console.log(ab);
console.log(o);

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

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

    vector<int> L(n);
    REP(i, n) cin >> L[i];
    sort(L.begin(), L.end());

    int ans = 0;
    REP(b, n) REP(a, b) {
        int ab = L[a] + L[b];
        int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
        int l = b + 1;
        ans += r - l;
    }

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n, ans = 0;
    cin >> n;
    for(ll i=1;(n-i)/i >= sqrt(n);++i) { // n/m
        if((n-i) % i == 0) {
            if(n-i == i) continue;
            ans += (n-i) / i;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    string a,b;
    cin >> a >> b;
    a += b;

    int n = 0;
    while(sz(a) > 0){
        n *= 10;
        n += (int)(a[0] - '0');
        a.erase(a.begin(),a.begin()+1);
    }
    //P(n);

    double d = sqrt(n);

    if((double)((int)d) == d)Yes;
    else No;

	
	return  0;
}

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

using namespace std;

const  int MAXN = 2123456;

int L[MAXN], R[MAXN], a[MAXN];

int main () {
	
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}

	for (int i = 1; i <= n; ++i) {
		L[i] = max (a[i-1], L[i-1]);
	}

	for (int i = n; i >= 0; --i) {
		R[i] = max (a[i+1], R[i+1]);
	}

	for (int i = 1; i <= n; ++i) 
		printf("%d\n", max (L[i], R[i]));


	return 0;
}


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

using namespace std;

int main(void) {
  int N, M, X;
  cin >> N >> M >> X;

  int C[N], A[N][M];
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }

  int ans = 1200001;
  for (int i = 0; i < (1 << N); i++) {
    int ct = 0, a[M];
    memset(a, 0, sizeof(a));

    for (int j = 0; j < N; j++) {
      if (i & (1 << j)) {
        ct += C[j];
        for (int k = 0; k < M; k++) {
          a[k] += A[j][k];
        }
      }
    }

    bool acv = true;
    for (int j = 0; j < M; j++) {
      if (a[j] < X) {
        acv = false;
      }
    }
    
    if (acv) {
      ans = min(ans, ct);
    }

  }

  if (ans == 1200001) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }

  return 0;
}

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

int32_t main(){
	ios::sync_with_stdio(false); cin.tie(0);
	string n;
	cin >> n;
    for(int i = 0; i < n.size()-1; ++i){
        if(n[i] == n[i+1]){
            cout << "Bad\n";
            return 0;
        }
    }
    cout << "Good\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long h,u,dp[1009][1009];
char a[1009][1009];
int main() {
    cin >> h>>u;
    for(int i=1;i<=h;i++)
    	for(int j=1;j<=u;j++)
    		cin>>a[i][j];
    for(int i=1;i<=h;i++)
    	for(int j=1;j<=u;j++)
    		if(i==1 && j==1)
    		    dp[1][1]=1;
    		else if(a[i][j]=='.')
    				dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%(long long)(pow(10,9)+7);
    cout<<dp[h][u];
}

Measured memory_bytes: 9216
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ll long long
const ll mod = pow(10,9) + 7;
int dp[101][6][6][6][6];
int N;
int p(int n, int a, int b, int c, int d){
    if(dp[n][a][b][c][d] != -1)
        return dp[n][a][b][c][d];
    if(a == 1 && c == 3 && d == 2)
        return 0;
    if(a == 1 && b == 3 && d == 2)
        return 0;
    if(b == 1 && c == 3 && d == 2)
        return 0;
    if(b == 1 && c == 2 && d == 3)
        return 0;
    if(b == 3 && c == 1 && d == 2)
        return 0;
    if(n == N)
        return 1;
    ll ans = 0;
    for(int i = 1; i < 5; i++)
        ans += p(n + 1, b, c, d, i);
    return dp[n][a][b][c][d] = ans % mod;
}
int main(){
    scanf("%d",&N);
    memset(dp, -1, sizeof(dp));
    printf("%d\n",p(0,5,5,5,5));
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long
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; }


signed main()
{
    string s; cin>>s;
    int N=s.size();
    int win=0;
    for(int i=0;i<N;i++){
        if(s[i]=='o') win++;
    }
    win+=15-N;
    cout<<(win>=8? "YES":"NO")<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long 
const int mod=1e9+7;
const int inf=1e9+7;

const int maxn=105;

int num[maxn];
 
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    
    int n;
    cin>>n;
    
    for(int i=0;i<n;i++)
    	cin>>num[i];
    
    ll int sum=0;
    
    for(int i=0;i<n;i++)
    {
    	for(int j=i+1;j<n;j++)
    	{
    		sum+=num[i]*num[j];
		}
	}
     
    cout<<sum<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
int main(void) {
    long long x, a, b, n, max, i;
    cin >> a;
    cin >> b;
    cin >> n;
    x = n;
    if (x > b)x = b - 1;
    max = (a * x / b) - a * (x / b);
    for (i = x - a; i <= x + a; i++) {
        if (i < 0)i = 0;
        if (i > n)break;
        if (max < (a * i / b) - a * (i / b))
            max = (a * i / b) - a * (i / b);
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 3624
import std.stdio;
import std.conv;
import std.string;

void main(){
    
    while(true){

	auto s = readln();
	if(stdin.eof()) break;
	int n = to!int(chomp(s));
	int m = 1;
	while(n > 0){
	    if(n % 2 == 1){
	       	writef("%d",m);
		n /= 2;
		if(n <= 0) break;
		writef(" ");
	    }else {
		n /= 2;
	    }
	    m *= 2;
	    }
	writeln("");
    }
}

Measured memory_bytes: 2468
import java.util.Scanner;

public class Main{
  static public void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    
    boolean flag = false;
    
    if(K == 1){
      flag = true;
    }else if((A % K) == 0 || (B % K) == 0){
      flag = true;
    }else{
      int mid = (A / K) + 1;
      int midK = K * mid;
      if(A <= midK && midK <= B){
        flag = true;
      }
    }
    
    if(flag){
      System.out.println("OK");
    }else{
      System.out.println("NG");
    }
    
  }
}

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

#include <stdio.h>
#include <string.h>

using namespace std;

typedef long long ll;

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

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

bool check(const string &S) {
    vector<char> stack;
    bool ok = true;

    for (int i = 0; i < (int) S.size(); i++) {
        char c = S[i];
        if (c == '(') {
            stack.push_back('(');
        } else if (c == '[') {
            stack.push_back('[');
        } else if (c == ')') {
            if (stack.empty()) {
                ok = false;
                break;
            }
            char prev = stack.back();
            stack.pop_back();
            if (prev != '(') {
                ok = false;
                break;
            }
        } else if (c == ']') {
            if (stack.empty()) {
                ok = false;
                break;
            }
            char prev = stack.back();
            stack.pop_back();
            if (prev != '[') {
                ok = false;
                break;
            }
        } else {
            // do nothing
        }
    }

    if (!stack.empty()) {
        ok = false;
    }

    return ok;
}

int main(void) {
    string S;
    char buf[128];
    int len;

    while (true) {
        fgets(buf, 128, stdin);
        len = strnlen(buf, 128);
        buf[len - 1] = '\0'; // remove newline
        S = string(buf);

        // cout << S << endl;
        if (S == ".") {
            break;
        }

        if (check(S)) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }

    return 0;
}




Measured memory_bytes: 3216
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
cnt = 0

if m == 0:
    if n == 1:
        print(0)
        exit()
    else:
        print(10**(n - 1))
        exit()
for i in range(1000):
    il = len(str(i))
    if il == n:
        for j in range(m):
            num = s[j][0] - 1
            k = str(i)
            if str(s[j][1]) == k[num]:
                cnt += 1
            num = 0
        if cnt == m:
            print(i)
            exit()
        else:
            cnt = 0
print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#include <stdio.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
using namespace std;

int main(void) {
    int t,a,b,j=2,power,sq=0;
cin>>a>>b;
 if(b>=100){
   t = a*1000+b;
 }else if(b>=10){
      t = a*100+b;
 }else if(b<10){
   t = a*10+b;
 }

sq = (int)sqrt(t);
if(t==(sq*sq)){
        cout<<"Yes"<<endl;
        return 0;
}

    // for(int i=2;i<=316;i++){
    //   power=i;
    //   while(j<=2){
    //     if(b>=100){
    //     if((a*1000+b)==power){
    //       cout<<"Yes"<<endl;
    //       return 0;
    //     }
    //   }else if(b>=10){
    //     if((a*100+b)==power){
    //       cout<<"Yes"<<endl;
    //       return 0;
    //     }
    //   }else if(b<10){
    //     if((a*10+b)==power){
    //       cout<<"Yes"<<endl;
    //       return 0;
    //     }
    //   }
    //     power *= i;
    //     j++;
    //   }
    //   j=2;
    // }
    cout<<"No"<<endl;
    return 0;
}


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

std::vector<int> makeKmpTable(const vector<int>& key) {
	const int length = key.size();
	std::vector<int> ret(length + 1);

	ret[0] = -1;
	int matched = -1;
	for (int i = 0; i < length; ++i) {
		while (matched >= 0 && key[matched] != key[i]) {
			matched = ret[matched];
		}
		++matched;
		if (key[i + 1] == key[matched]) {
			ret[i + 1] = ret[matched];
		} else {
			ret[i + 1] = matched;
		}
	}
	return ret;
}

std::vector<int> findAllKmp(const vector<int>& str, const vector<int>& key) {
	const std::vector<int> table = makeKmpTable(key);
	std::vector<int> ret;

	int pos = 0;
	int i = 0;
	while (pos + key.size() <= str.size()) {
		while (str[pos + i] == key[i]) {
			++i;
			if (i == key.size()) {
				ret.push_back(pos);
				break;
			}
		}
		pos += i - table[i];
		i = std::max(table[i], 0);
	}
	return ret;
}

int n;
vector<int> cat(vector<int> a, vector<int> b) {
  for (int i = 0; i < n - 1; ++i) {
    a.push_back(a[i]);
  }
  return findAllKmp(a, b);
}

vector<int> sub(vector<int> p) {
  vector<int> ret;
  for (int i = 0; i < n; ++i) {
    ret.push_back((p[i] ^ p[(i + 1) % n]) + 1); 
  }
  return ret;
}

int main() {
  cin >> n;
  vector<int> a, b, c, d;
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    a.push_back(v);
  }
  for (int i = 0; i < n; ++i) {
    int v;
    cin >> v;
    b.push_back(v);
  }
  
  c = sub(a);
  d = sub(b);
  
  auto res = cat(c, d);
  for (int i : res) {
    cout << i << ' ' << (a[i] ^ b[0]) << endl;
  }
}

Measured memory_bytes: 8276
using System;

public class hello
{
    public static void Main()
    {
        string line;
        for (; (line = Console.ReadLine()) != null;)
        {
            var a = double.Parse(line.Trim());
            var sum10 = 0d;
            for (int i = 1; i < 11; i++)
                sum10 += Seq(a, i);
            Console.WriteLine(sum10);
        }
    }
    public static double Seq (double a , int  n)
    {
        var res = 0d;
        if (n == 1)
        {
            return a;
        }
        if (n % 2 == 0)
        {
            res = Seq(a, n - 1) * 2;
            return res;
        }
        else
        {
            res = Seq(a, n - 1) / 3;
            return res;
        }
    }
}

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

int main()
{
    ll h, w;
    cin >> h >> w;
    ll ans;
    if(h % 2 == 0){
        ans = ((h + 1) / 2) * w;
    }else if(w % 2 == 0){
        ans = ((w + 1) / 2) * h;
    }else{
        ans = ((h + 1) / 2) * (w / 2 + 1) +
        ((h + 1) /2 - 1) * (w / 2);
    }

    if(h == 1 || w == 1) ans = 1;
    cout << ans << endl;

    return 0;
}


// int main()
// {
//     ll a, b, c;
//     cin >> a >> b >> c;
//     if((c - a - b) > sqrt(LLONG_MAX) || 2 * sqrt(a * b) > sqrt(LLONG_MAX)){
//         if(sqrt(a) + sqrt(b) < sqrt(c)) cout << "Yes" << endl;
//         else cout << "No" << endl;
//     }

//     if((c - a - b) * (c - a - b) > 4 * a * b) cout << "Yes" << endl;
//     else cout << "No" << endl;

//     return 0;
// }

Measured memory_bytes: 256
score_list = []
count = 0
while True:
    m, f, r = list(map(int, input().split()))
    if m == -1 and f == -1 and r == -1:
        break
    elif m == -1 or f == -1:
        score_list.append('F')
    elif m + f >= 80:
        score_list.append('A')
    elif m + f >= 65:
        score_list.append('B')
    elif m + f >= 50:
        score_list.append('C')
    elif m + f >= 30:
        if r >= 50:
            score_list.append('C')
        else:
            score_list.append('D')
    else:
        score_list.append('F')
    count+=1

for i in range(count):
    print(score_list[i])


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

int main() {
	//input
	int H, N;
	cin >> H >> N;

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

	//calculation
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += A[i];
	}
	if (sum >= H) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
    char x, y;
    cin >> x >> y;

    if(x<y) cout << '<' <<endl;
    else if(x==y) cout << '=' <<endl;
    else if(x>y) cout << '>' <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <map>

int main(){

  int N;
  scanf("%d\n",&N);
  std::map<int, int> A;
  int temp;
  for (int i=0; i<N; i++){
    scanf("%d",&temp);
    A.insert(std::make_pair(temp,i+1));
  }
  for (auto const& entry: A)
    {
        std::cout << entry.second << " ";
    }
  std::cout<<"\n";
  return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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 const INF = 1001001001;


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

int x,y;
cin >> x >> y;
x--; y--;
vi A(12,0);
rep(i,12) {
    if(i == 3 || i == 5 || i == 8 || i == 10) A[i] = 1;
    if(i == 1) A[i] = 2;
}
if(A[x] == A[y]) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()
 
template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
 
#define int ll
const int MAXN = 210;
int G[MAXN][MAXN];
 
int gcd(int a, int b, int c) {
	return G[a][G[b][c]];
}
 
void read() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			G[i][j] = __gcd(i, j);
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			for (int k = 1; k <= n; k++) {
				ans += gcd(i, j, k);
			}
		}
	}
	cout << ans << endl;
}
 
void run() {
 
}
 
void write() {
 
}
 
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	read();
	run();
	write();
	return 0;
}

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

using namespace std;


int w, h;

int isBomb(vector<string> map, int x, int y) {
  if (x < 0 || w <= x || y < 0 || h <= y) {
    return 0;
  }
  return map[y][x] == '#' ? 1 : 0;
}

int main() {
  cin >> h >> w;
  vector<string> map(h);
  for (int i = 0; i < h; i++) {
    cin >> map[i];
  }
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (isBomb(map, x, y)) {
        cout << '#';
        continue;
      }
	  cout << (
        isBomb(map, x - 1, y - 1) +
        isBomb(map, x - 1, y) +
        isBomb(map, x - 1, y + 1) +
        isBomb(map, x, y - 1) +
        isBomb(map, x, y + 1) +
        isBomb(map, x + 1, y - 1) +
        isBomb(map, x + 1, y) +
        isBomb(map, x + 1, y + 1)
      );
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    mod = 7 + 10 ** 9
    S = 1
    while S ** 2 <= N:
        S += 1
    DP = [[[0, 0] for _ in range(S)] for _ in range(K)]
    Rev = [0] * S
    S -= 1
    Rev[S] = (N // S - S) % mod
    for i in reversed(range(1, S)):
        Rev[i] = ((N // i) - (N // (i + 1))) % mod
    for i in range(1, S + 1):
        DP[0][i][0] = 1
        DP[0][i][1] = Rev[i]
    for i in range(2, S + 1):
        DP[0][i][0] += DP[0][i-1][0]
        DP[0][i][0] %= mod
    DP[0][S][1] += DP[0][S][0]
    DP[0][S][1] %= mod
    for i in reversed(range(1, S)):
        DP[0][i][1] += DP[0][i+1][1]
        DP[0][i][1] %= mod

    for i in range(1, K):
        for j in range(1, S + 1):
            DP[i][j][0] += DP[i-1][j][1]
            DP[i][j][1] += (DP[i-1][j][0] * Rev[j]) % mod
            DP[i][j][1] %= mod
            DP[i][j][0] += DP[i][j-1][0]
            DP[i][j][0] %= mod
        DP[i][S][1] += DP[i][S][0]
        DP[i][S][1] %= mod
        for j in reversed(range(1, S)):
            DP[i][j][1] += DP[i][j+1][1]
            DP[i][j][1] %= mod

    print(DP[K-1][1][1])
    #print(DP)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 350372
import math

if __name__=="__main__":
    n = int(input())
    X = [int(a) for a in input().split()]

    sum_x = sum(X)

    sum_x2 = 0
    for x in X:
        sum_x2 += x**2
    
    z = math.floor(sum_x/n)
    r = sum_x/n - z

    if r <= 0.5:
        ans = sum_x2 + n*z**2 - 2*z*sum_x
    else:
        ans = n - 2*(1+z)*sum_x + 2*z*n + z**2*n + sum_x2

    print(ans)

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

#define ll long long int

set<pair<ll, ll> > s;

void primeFactors(ll n)  
{  
	ll k=0;
    while (n % 2 == 0)  
    {  
    	k++;
        n = n/2;  
    }  
    if(k != 0)	
    {
		s.insert(make_pair(2, k));
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)  
    {  
    	k=0;
        while (n % i == 0)  
        {  
           	k++;
            n = n/i;  
        }  
        if(k!=0)	s.insert(make_pair(i, k));
    }  
  
    if (n > 2)  
        s.insert(make_pair(n, 1));
}

ll solve(ll t)
{
	ll ans;
	for(int i=0;i<50;i++)
	{
		if((i*(i+1))/2 <= t)	ans = i;
	}
	return ans;
}

int main()
{
	ll n, ans=0;
	cin >> n;
	primeFactors(n);
	set<pair<ll, ll> >::iterator it = s.begin();
	while(it != s.end())
	{
		ll t = it->second;
		ans += solve(t);
		it++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3680
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
// #include <map>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 

const int maxn = 2e5;
int a[maxn][3];
int d[maxn][3];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < 3; ++j){
			cin >> a[i][j];
		}
	}
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < 3; ++j){
			d[i][j] = max(d[i - 1][(j + 1) % 3] + a[i][j], d[i - 1][(j + 2) % 3] + a[i][j]);
		}
	}
	cout << *max_element(d[n], d[n] + 3) << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

int main() {

    int n;
    cin >> n;
    ll a[n];
    long long dp[n][n];

    for(int i = 0; i < n; ++i) 
        cin >> a[i];

    for(int l = 0; l < n; ++l) {

        for(int r = l; r >= 0; --r) {

            if(l == r)
                dp[l][r] = a[r];
            else
                dp[l][r] = max(a[l] - dp[l-1][r], a[r] - dp[l][r+1]);
            // for(int i = 0; i < n; ++i) {
            //     for(int j = 0; j < n; ++j) {
            //         cout << dp[i][j] << " ";
            //     }
            //     cout << endl;
            // }
        }
    }

    cout << dp[n-1][0];

    return 0;
}

Measured memory_bytes: 70400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>

using namespace std;
typedef pair<int, int> P;

void solve()
{
	int N;
	cin >> N;
	if (N % 10 == 0)
	{
		cout << 10 << endl;
	}
	else
	{
		int ans = 0;
		while (N)
		{
			ans += N % 10;
			N /= 10;
		}
		cout << ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    static String[] ANS = { "Three", "Four" };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());

        Set<String> set = new HashSet<>();
        for (int i = 0; i < N; i++) {
            set.add(sc.next());
        }

        System.out.println(ANS[set.size() - 3]);
    }
}


Measured memory_bytes: 21332
import qualified Data.ByteString.Char8 as C
import Data.List
import Control.Monad

import qualified Data.IntMap as M
import qualified Data.Sequence as S

import Data.Foldable(toList)
import Data.Maybe(fromMaybe)


r :: IO [Int]
r  = unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine
    where toTup [a,b] = (a,b)


main :: IO ()
main = do
    n <- readLn :: IO Int
    print $ div (n*(n-1)) 2



Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        var s = sc.longarr;
        long n = s[0];
        long m = s[1];
        long ans = 0;
        if (m * n == 1)
        {
            ans = 1;
        }
        else if (n == 1)
        {
            ans = m - 2;
        }
        else if (m == 1)
        {
            ans = n - 2;
        }
        else
        {
            ans = Math.Max(0, n - 2) * Math.Max(0, m - 2);
        }
        wr.wri(ans);

    }

}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => strarr.Select(char.Parse).ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


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

int main(){
 string str1, str2;
 int n;
 
 cin >> str1 >> str2;
 
 n = str2.size();
 str2.erase(n - 1);

 if(str1 == str2){
 	cout << "Yes" << endl;
 }
 else{
 	cout << "No" << endl;
 }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vector<string> p(N);
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    ll ans = 1;
    for(int i=1; i<N; i++){
        if(p[i] != p[i-1]){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 9600
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


# import numpy as np
N, K = read_ints()
# H = np.array(read_ints())
# K = min(len(H), K)

# dp = np.full((N), np.inf)
# dp[0] = 0
# # Kまで初期化しておかないと厄介なことになる
# # i-kのコストは直接飛ぶのが必ず最小になる
# dp[1:K+1] = np.abs(H[0]-H[1:K+1])

# for i in range(K+1, N):
#     # i-Kまでのコストリストを作成しておく
#     dp[i] = (dp[(i - K):(i)] + np.abs(H[i] - H[(i - K):(i)])).min()


# print(int(dp[-1]))


# 配るDPでもやる

K = min(N, K)
H = read_ints() + [0 for _ in range(K)]
# H = np.array(H)
# dp = np.full((N + K), np.inf)
dp = [float('inf') for _ in range(N+K)]
dp[0] = 0
for i in range(N):
    # 配るDPでやる
    for k in range(1, K+1):
        dp[i + k] = min(dp[i + k], dp[i] + abs(H[i] - H[i + k]))

# print(dp)
print(int(dp[N-1]))


Measured memory_bytes: 57564
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<vector>
#include<list>
#include<queue>
#include<map>
using namespace std;

int main(){
	int i, j, k, n, m, a, b;
	char s[55], t[55];

	scanf("%s", s);
	scanf("%s", t);
	int slen = strlen(s);
	int tlen = strlen(t);

	for (i = slen - tlen; i >= 0; i--) {
		for (j = 0; j < tlen; j++) {
			if (s[i+j] == '?') continue;
			else if (s[i+j] != t[j]) break;
		}

		if (j == tlen) {
			for (j = 0; j < tlen; j++) {
				s[i+j] = t[j];
			}
			for (j = 0; j < slen; j++){
				if (s[j] == '?') s[j] = 'a';
			}
			printf("%s\n", s);
			break;
		}
	}
	if (i == -1) printf("UNRESTORABLE\n");

	return 0;
}


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

int main(){
  int n,x,t,ans=0;
  cin >> n >> x >> t;
  while(true){
    n -= x;
    ans += t;
    if(n<=0) break;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
import itertools

def powerset(seq, m):
	return [ list(u) for u in itertools.product(*([seq]*m) ) ]

def cnt(seq,v):
	return len([x for x in seq if x==v])

def main():
	N,a,b,c = map(int, raw_input().split())
	ls = [input() for _ in range(N)]
	res = 10**9
	for vs in powerset([0,1,2,3], N):
		aa = []
		bb = []
		cc = []
		for i in range(N):
			if vs[i]==0:aa.append(ls[i])
			elif vs[i]==1:bb.append(ls[i])
			elif vs[i]==2:cc.append(ls[i])
			else:
				assert vs[i]==3
		if len(aa)==0 or len(bb)==0 or len(cc)==0:continue
		res=min(res, abs(a-sum(aa))+abs(b-sum(bb))+abs(c-sum(cc))+10*(len(aa)-1 + len(bb)-1 + len(cc)-1)  )
	print res
	
	return 0

if __name__ == '__main__':
	main()



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

using namespace std;

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

  int maximum = 1;
  int minimum = 1000000000;

  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;

    maximum = max(maximum, A);
    minimum = min(minimum, A);
  }

  int answer = maximum - minimum;

  cout << answer << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define rep(i,l,r)for(ll i=l;i<r;i++)

typedef long long ll;

char s[3][101];
ll len[3];

int f(int n) {
	if (len[n] == strlen(s[n])) return n;
  	char c=s[n][len[n]];
	len[n]++;
	return f(c - 'a');
}

int main(){
	rep(i, 0, 3) scanf("%s", s[i]);
	printf("%c\n", f(0)+'A');

	return 0;
}

Measured memory_bytes: 2148
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
  long N, result = 0;
  int min_index = 0;
  long A[5] = {0};
  long min = 10e+15;
  cin >> N;
  for(int i=0;i < 5;i++){
    cin >> A[i];  
  }
  for(int i=0;i < 5;i++){
    if(A[i] < min){
      min_index = i;
      min = A[i];
    }
  }
  if(N % A[ min_index] == 0){
    result = N / A[min_index] + 4;
  }else{
    result = N / A[min_index] + 1 + 4;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
import Control.Monad (replicateM)

main = do
    [n,k] <- fmap read . words <$> getLine
    zs <-  fmap (fmap read . words) <$> replicateM n getLine
    let rs = fmap (\[x,y] -> (x,y)) zs
    let (xs,ys) = unzip rs
    print $ minimum [ s | x1 <- xs, y1 <- ys,
                    x2 <- xs, y2 <- ys,
                    x1<x2 && y1<y2,
                    let s = (x2-x1)*(y2-y1)
                        m = length $ filter (\(a,b) -> x1<=a&&a<=x2&&y1<=b&&b<=y2) rs,
                    m >= k ]

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=1001 ;
ll  power(ll  i,ll  j,ll mod)
{
    ll maa=mod ;
    
    if(j==0)
    return 1 ;
    ll t=power(i,j/2,maa)%maa ;
    if(j%2==0)
    return (t%maa*t%maa)%maa ;
    else
    return ((t%maa*t%maa)%maa*(i%maa)%maa)%maa ;
}
int main()
{
   fast ;
   ll n,pr ;
   cin>>n>>pr ;
   char r[n+1] ;
   r[0]='0' ;
   
   for(ll i=1;i<=n;i++)
   cin>>r[i] ;
   
   ll p[n+1] ;
   p[0]=0 ;
   ll lol[n+1] ;
   lol[0]=0 ;
   for(ll i=1;i<=n;i++)
   {
     p[i]=p[i-1]*10+(r[i]-'0') ;
     p[i]%=pr ;
     lol[i]=p[i] ;
   }
   for(ll i=1;i<=n;i++)
   {
       ll x=power(10,i,pr) ;
       x=power(x,pr-2,pr) ;
       p[i]=(p[i]*x)%pr ;
      
   }
   map<ll,ll>ma ;
   ll ans=0 ;
   ma[0]++ ;
   
   for(ll i=1;i<=n;i++)
   {
      ll x=power(10,i,pr) ;
      if(lol[i]==0)
      {
          if(x==0)
          {
              ans+=i ;
          }
          else
          {
              ans+=ma[0] ;
          }
      }
      else
      {
          if(x!=0)
          {
              ll y=(lol[i]*power(x,pr-2,pr))%pr ; 
              ans+=ma[y] ;
          }
      }
      
      ma[p[i]]++ ;
   }
   cout<<ans ;
   

}


Measured memory_bytes: 6016
import sys
readline = sys.stdin.readline
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

def round(f, r=0):
    return Decimal(str(f)).quantize(Decimal(str(r)), rounding=ROUND_HALF_UP)

def main():
    H, W = map(int, readline().rstrip().split())
    ans = H * W
    if H >= 3:
        y1 = int(round(H/3))
        y2 = (H-y1) // 2
        y3 = H - y1 - y2
        ans = min(ans, max(W*y1, W*y2, W*y3)-min(W*y1, W*y2, W*y3))
    if W >= 3:
        x1 = int(round(W/3))
        x2 = (W-x1) // 2
        x3 = W - x1 - x2
        ans = min(ans, max(x1*H, x2*H, x3*H)-min(x1*H, x2*H, x3*H))
    
    # 縦にスライス + 残りに横にスライス
    x1 = int(round(W/3))
    y1 = H
    x2 = W - x1
    x3 = x2
    y2 = H // 2
    y3 = H - y2
    ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

    # 横にスライス + 残りに縦にスライス
    y1 = int(round(H/3))
    x1 = W
    y2 = H - y1
    y3 = y2
    x2 = W // 2
    x3 = W - x2
    ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  int n;
  int p1 = 0;
  int p2 = 0;
  cin >> n;
  string a, b;
  for(int i = 0 ; i < n ; i ++) {
    cin >> a >> b;
    if( a > b) {
      p1 += 3;
    } else if ( a == b) {
      p1 += 1;
      p2 += 1;
    } else {
      p2 += 3;
    }
  }
  cout << p1 << " " << p2 << endl;

}

Measured memory_bytes: 3164
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, M, A[1 << 18], B[1 << 18];
int c1[1 << 18], c2[1 << 18];
vector<int> X[1 << 18];

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(B[i]);
		X[B[i]].push_back(A[i]);
	}
	for (int i : X[1]) c1[i] = 1;
	for (int i : X[N]) c2[i] = 1;
	for (int i = 1; i <= N; i++) {
		if (c1[i] + c2[i] == 2) { cout << "POSSIBLE" << endl; return 0; }
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 19600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define INF 1000000
#define watch(x) cout << setw(10) << "[" << (#x) << ":] " << (x) 
#define FORE(i,v,n) for(int i=v;i<n;i++)
#define FORI(i,v,n) for(int i=v;i<=n;i++)
#define vi vector<int>;
#define pii pair<int, int>

using namespace std;
using namespace __gnu_pbds;

//typedef tree <int, null_type, less<int> rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int const MOD = 1000000007;

int test_case(){
	unsigned long long int n,a,b;
	cin >> n >> a >> b;
	if(a == 0) {
		cout << 0 << endl;
		return 0;
	}
	else{
		//cout << ((n/(a+b))*a + n%(a+b)); cout << endl;
		unsigned long long int answer = (n/(a+b))*a;
		answer += min(n%(a+b), a);
		cout << answer << endl;
	}
	
	return 0;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int test=1;
	//cin >> test;
	for(int i=0;i<test;i++){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 256
// Optimised solution (Saves space)
// Converted matrix to an array
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define dbg(x) { cerr<<"> "<<#x<<": "<<x<< endl; }
#define dbg2(x,y) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z) { cerr<<"> "<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif

const int inf = INT_MAX;
const int MOD = 1e9 + 7;
const int N = 105;

int w[N], v[N];
int dp[100005];

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i < 100005; i++)
        dp[i] = inf;
    for (int i = 1; i <= n; i++) {
        // Reverse loop
        for (int j = 100004; j >= 1; j--) {
            if (j >= v[i])
                dp[j] = min(dp[j], dp[j-v[i]] + w[i]);
        }
    }
    int ans = 0;
    for (int i = 0; i < 100005; i++)
        if (dp[i] <= k) ans = i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
from collections import namedtuple
from functools import partial
from operator import attrgetter

Path = namedtuple('Path', ('length', 'left_seat', 'right_seat'))

m = set()
f = set()


def is_suitable_path(p: 'Path', m: 'set', f: 'set') -> 'bool':
    if p.length <= 1:
        return False
    if p.length % 2 == 0:
        return (p.left_seat in m and p.right_seat in f) or (p.left_seat in f and p.right_seat in m)
    else:
        return (p.left_seat in m and p.right_seat in m) or (p.left_seat in f and p.right_seat in f)


is_suitable_path = partial(is_suitable_path, m=m, f=f)

n = int(input())

checked = [n]
x = 0
for _ in range(20):
    print(x)

    checked.append(x)
    checked.sort()

    res = input()
    if res[0] == 'V':
        break
    else:
        if res[0] == 'M':
            m.add(x)
            if x == 0:
                m.add(n)
        else:
            f.add(x)
            if x == 0:
                f.add(n)

        t = sorted(filter(is_suitable_path,
                          (Path(length=t - s, left_seat=s, right_seat=t) for s, t in zip(checked, checked[1:]))),
                   key=attrgetter('length'))
        x = (t[0].left_seat + t[0].right_seat) // 2


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

int cnt;

void insertionSort(int* a, int n, int g){

    int i, j, v;

    for(i = g; i < n; i++){
        v = a[i];
        j = i - g;
        while((j >= 0) && (a[j] > v)){
            a[j + g] = a[j];
            j = j - g;
            cnt++;
        };
        a[j + g] = v;
    }
}

void shellsort(int* a, int n)
{
    cnt = 0;
    int i, p;
    int m;
    int G[15];

    p = 1;
    for(i = 1; i < 20; i++){
        p = p * 3;
        if(p - 1 > 2 * n) break;
    }
    if(i > 1) i = i - 1;
    m = i;

    p = 1;
    for(i = 0; i < m; i++){
        p = p * 3;
        G[m - 1 - i] = (p - 1) / 2;
    }
    cout << m << endl;
    for(i = 0; i < m - 1; i++) cout << G[i] << " ";
    cout << G[m - 1] << endl;

    for(int i = 0; i < m; i++){
        insertionSort(a, n, G[i]);
    }
}

int main()
{
    int* A;
    int i, n;
    cin >> n;

    A = new int [n];
    if(A == NULL) return 0;

    for(i = 0; i < n; i++) cin >> A[i];

    shellsort(A, n);
    cout << cnt << endl;
    for(i = 0; i < n; i++) cout << A[i] << endl;

    return 0;
}

Measured memory_bytes: 5084
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().strip().split()]
    f, p = 0, 0
    ans = 0
    for a in A:
        if f == 1:
            if a > p:
                f = 2
            elif a < p:
                f = 3
        elif f == 2:
            if a < p:
                ans += 1
                f = 1
        elif f == 3:
            if a > p:
                ans += 1
                f = 1
        elif f == 0:
            f = 1
        p = a
    else:
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()

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

int a[2005];

bitset<2005*2005> dp;

int main()
{

    int n, sum = 0;

    scanf("%d", &n);

    for(int i = 1; i<=n; i++){
        scanf("%d", &a[i]);
        sum += a[i];
    }

    dp[0] = 1;

    for(int i = 1; i<=n; i++){
        dp |= dp<<a[i];
    }

    for(int i = (sum+1)/2; i<=sum; i++){
        if(dp[i]){
            cout<<i<<endl;
            return 0;
        }
    }

    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 string a;
 cin>>a;
 int n= a.length(),f=0;
 if(n==1)
    cout<<"0";
 else{
 if(n%2==1)
 {
     f=1;
 }
 int i=0,j=n-1,c=0;
 while(1){
    if(a[i]!=a[j])
    {
        c++;
    }
    i++,j--;
    if(i==j && f==1)
        break;
    if((i-1)==(j) && f==0)
      break;

 }
cout<<c;
}}


Measured memory_bytes: 3616
#include<stdio.h>
int main(){
  int sum,a[9],i;
  while(1){
    scanf("%d",&sum);
    if(sum==0)break;
    for(i=0;i<9;i++){
      scanf("%d",&a[i]);
      sum-=a[i];
    }
    printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 1028
#!/usr/bin/python --
import sys

#2007 Domestic A
def judge(n):
  ma=0
  mi=1000
  s=0
  for i in range(0,n):
    x=int(sys.stdin.readline())
    if x<mi:
      mi=x
    if x>ma:
      ma=x
    s+=x
  print (s-ma-mi)/(n-2)

while 1:
  n=int(sys.stdin.readline())
  if n==0:
    break
  judge(n)

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;

string s;
string rs;
int main()
{
    cin >> s;
    rs = s;
    reverse(ALL(rs));
    if (s == rs)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

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

using namespace std;

int main(){
  int K;
  string S;
  cin >> K;
  cin >> S;
  if(S.length()<=K){
    cout << S;
  }else{
    cout << S.substr(0,K);
    cout << "...";
  }
  return 0;
}


Measured memory_bytes: 3568