akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)
#define all(c) c.begin(), c.end()
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int n;
	while(cin>>n && n){
		vvi g(5,vi(n));
		rep(i,n)rep(j,5)cin>>g[j][i];
		rep(i,5)reverse(all(g[i]));
		
		int ans=0;
		while(1){
			int t=0;
			rep(i,5){
				rep(j,g[i].size()){
					int ni=i;
					if(g[i][j]==-1) continue;
					while(ni < 5 && j < g[ni].size() && g[ni][j]==g[i][j]){
						ni++;
					}
					if(ni-i<3) continue;
					for(int ii=i;ii<ni;ii++){
						t+=g[ii][j];
						g[ii][j] = -1;
					}
				}
			}
			if(t==0)break;
			// rep(i,5){
			// 	rep(j,g[i].size()){
			// 		cout << g[i][j] << " ";
			// 	}
			// 	cout<<endl;
			// }
			rep(i,5)g[i].erase(remove(all(g[i]),-1),g[i].end());
			ans+=t;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1212
s = list(input())

if s[0]!="A":
    print("WA")
    exit()
else:
    del s[0]
cnt=0
for i in range (1,len(s)-1):
    if s[i]=="C":
        cnt+=1
    
if cnt==1:
    del s[s.index("C")]
else:
    print("WA")
    exit()

for i in range(len(s)):
    if s[i].islower()==True:
        continue
    else:
        print("WA")
        exit()

print("AC")        

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
 int N;
 double x,num;
 char u[3];
  
 scanf("%d",&N);
  
  for(int a=0;a<N;a++){
  scanf("%lf %s",&x,u);
    
  if(u[0]=='J')
    num = num +x;
  else if(u[0]=='B')
    num = num + (x*380000);
  }
  
  
  printf("%.4f\n",num);
  
  
return 0;
}

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

int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int h,w,cnt;
char g[100][100];
bool vis[100][100];

void dfs(int x,int y)
{
	cnt++;
	for(int i=0;i<4;i++){
		int nx=dx[i]+x,ny=dy[i]+y;
		if(nx<=0||ny<=0||nx>h||ny>w) continue;
		if(vis[nx][ny]) continue;
		if(g[nx][ny]=='.') continue;
		vis[nx][ny]=true;
		dfs(nx,ny);
	}
}

int main()
{
    cin>>h>>w;
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) cin>>g[i][j];
    for(int i=1;i<=h;i++) for(int j=1;j<=w;j++) if(!vis[i][j]&&g[i][j]=='#'){
    	cnt=0;
    	dfs(i,j);
    	if(cnt==1){
    		cout<<"No"<<endl;
    		return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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(b<a){a=b;return 1;}return 0;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	lint n,sum=0,count=0;
	cin>>n;
	while(1){
		count++;
		if(count%3==0||count%5==0){
		}else{
			sum+=count;
		}
		if(count==n)break;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3652
n = int(input())
a = [int(i) for i in input().split()]
minA = a[0]
step = 0
for i in range(n - 1):
    if a[i + 1] > minA:
        minA = a[i + 1]
    else:
        step += (minA - a[i + 1])
print(step)

Measured memory_bytes: 32324
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int nh[] = {-1, 0, 0, 1};
int nw[] = {0, -1, 1, 0};
void solve(int w, int h) {
    VVI mini(h, VI(w, INF));
    auto inside = [&h, &w](int nh, int nw) {
        return 0 <= nw && nw < w && 0 <= nh && nh < h;
    };
    vector<vector<VPII>> graph(h, vector<VPII>(w));
    REP(i, h) {
        int in;
        REP(j, w - 1) {
            cin >> in;
            if (in) continue;
            graph[i][j].EB(MP(i, j + 1));
            graph[i][j + 1].EB(MP(i, j));
        }
        if (i != h - 1) REP(j, w) {
            cin >> in;
            if (in) continue;
            graph[i][j].EB(MP(i + 1, j));
            graph[i + 1][j].EB(MP(i, j));
        }
    }
    queue<PII> q;
    q.push(MP(0, 0));
    mini[0][0] = 1;
    while (!q.empty()) {
        int nw, nh;
        tie(nh, nw) = q.front();q.pop();
        FORE(e, graph[nh][nw]) {
            if (!inside(e.first, e.second)) continue;
            if (mini[e.first][e.second] != INF) continue;
            mini[e.first][e.second] = mini[nh][nw] + 1;
            q.push(MP(e.first, e.second));
        }
    }
    if (mini[h - 1][w - 1] == INF) mini[h - 1][w - 1] = 0;
    cout << mini[h - 1][w - 1] << endl;
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n >> m, n) {
        solve(n, m);
        //return 0;
    }
}

Measured memory_bytes: 3168
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set>
using namespace std;

int main()
{
	int n,a[100010];
	scanf("%d",&n);
	for (int i=1; i<=n;i++)
		scanf("%d",&a[i]);
	int num =0;
	int pair[100010];
	memset(pair,0,sizeof(pair));
	for (int i=1; i<=n;i++)
		if (pair[i] != 1)
		{
			if (a[a[i]] == i)
			{
				num++;
				pair[i] = 1;
				pair[a[i]] = 1;
			}
		}

	printf("%d\n", num);
	return 0;
}

Measured memory_bytes: 1024
/*Author SHUBH AGRAWAL  */

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
//a power n mod p

#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 

long long int modp(lld a,lld p,lld n)
{
    int d[100];
    int i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

long long int nCrModPFermat(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
    
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    lld fac[n+1]; 
    fac[0] = 1; 
    for (lld i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}


lld l,r,mid,ans;
lld n,m,i,j,k;
lld x,w,y,z;
lld n1,n2,m1,m2;

void solve()
{
    cin>>x>>y;
    if(x%2==0)
    {
        n1=(25*x)/2;
        n2=(25*(x+1))/2;
    }
    else
    {
        n1=(25*x)/2+1;
        n2=(25*(x+1))/2-1;
    }
    m1=10*y;
    m2=10*y+9;
    if(n1>m1)
    {
        if(n1>m2) cout<<"-1";
        else cout<<n1;
    }
    else if(n1==m1)  cout<<n1;
    else
    {
        if(m1>n2) cout<<"-1";
        else cout<<m1;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

#define fs first
#define sc second
using namespace std;

typedef pair<int,int> P;
typedef pair<P,P> P2;

int x,y;
int mas[50][50][50][50];
int depart[50][50];
int ax,ay,bx,by;

int main(){
  for(;;){
    cin >> x >> y;
    if(!x && !y)break;

    cin >> ax >> ay >> bx >> by;

    for(int i=0;i<y;i++)
      for(int j=0;j<x;j++){
	cin >> depart[i][j];
	for(int k=0;k<y;k++)
	  for(int l=0;l<x;l++)mas[i][j][k][l] = -1;
      }

    mas[ay-1][ax-1][by-1][bx-1] = 0;
    queue<P2> q;
    q.push(P2(P(ay-1,ax-1),P(by-1,bx-1)));

    int ans = -1;
    while(q.size()){
      P2 p = q.front();q.pop();
      int ky = p.fs.fs, kx = p.fs.sc;
      int ty = p.sc.fs, tx = p.sc.sc;
      //cout << ky << " " << kx << " " << ty << " " << tx<< endl;
      if(ky==ty && kx==tx){
	ans = mas[ky][kx][ty][tx];
	break;
      }
      if(mas[ky][kx][ty][tx]>=100)break;

      int dx[] = {0,1,0,-1},dy[] = {-1,0,1,0};
      for(int i=0;i<4;i++){
	int sky = ky+dy[i], skx = kx+dx[i];
	int sty = ty-dy[i], stx = tx-dx[i];
	bool f1 = (sky<0 || skx<0 || y<=sky || x<=skx || depart[sky][skx]);
	bool f2 = (sty<0 || stx<0 || y<=sty || x<=stx || depart[sty][stx]);
	if(f1 && f2)continue;
	if(f1 && !f2){
	  sky = ky;
	  skx = kx;
	}
	if(!f1 && f2){
	  sty = ty;
	  stx = tx;
	}
	if(mas[sky][skx][sty][stx]>=0)continue;
	mas[sky][skx][sty][stx] = mas[ky][kx][ty][tx] + 1;
	q.push(P2(P(sky,skx),P(sty,stx)));
      }
    }
    if(ans<0)cout << "NA\n";
    else cout << ans << endl;
  }
}

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

#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using sl = stack<ll>;
using ql = queue<ll>;

const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};


void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

int binary_search(ll x, vl a){
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin() ;
    } else {
        return -1;
    }

}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll MOD = 1000000007;
    ll N, num, sum = 0, ans = 0;
    cin >> N;
    vl A(N), S(N);
    REP(i, N) {
        cin >> num;
        A[i] = num;
        sum += num;
        S[i] = sum;
    }
    REP(i, N-1){
        num = S[N-1] - S[i];
        num %= MOD;
        ans += A[i] * num;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
long long gcd(long long a, long long b);
long long lcm(long long a, long long b);



void solve()
{
    int n;
    cin >> n;
    ll a[n];
    REP(i, n) cin >> a[i];
    ll yakusuu = a[0];
    for(int i = 1; i < n; i++) yakusuu = gcd(yakusuu, a[i]);
    int ans = 0;
    while(yakusuu % 2 == 0){
        ans++;
        yakusuu /= 2;
    }
    cout << ans << "\n";
}

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

/*long C(long n, long r){
    if(n < r) return 0;
    long p[n+1][n+1];
    p[0][0] = 1;
    for(int i = 1; i <= n; i++){
        p[i][0] = 1;
        p[i][i] = 1;
        for(int j = 1; j <= i-1; j++){
            p[i][j] = p[i-1][j] + p[i-1][j-1];
        }
    }
    return p[n][r];
}*/

long long gcd(long long a, long long b){
    if(a < b) swap(a, b);
    if(a % b == 0) {
        return b;
    }
    else{
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<bitset>
using namespace std;

const int NONE = -1;

const int DY[4] = {0, 1, 0, -1};
const int DX[4] = {1, 0, -1, 0};

enum{TIME, Y, X, BOUGHT};
typedef tuple<int, int, int, unsigned long> Vertex;

enum {GOODS, DISCOUNT, START, END};
typedef tuple<int, int, int, int> Sale;

int h, w;
int n;
vector<vector<int>> m;
vector<Sale> sale;

int sum(unsigned long bought) {
    int result = 0;
    bitset<8> b(bought);
    for(int i = 0; i < n; ++i) if(b[i]) result += get<DISCOUNT>(sale[i]);
    return result;
}

int bfs(const Vertex& start) {
    int result = 0;
    vector<vector<vector<vector<int>>>> memo(101, vector<vector<vector<int>>>(h, vector<vector<int>>(w, vector<int>(1 << 8, -1))));
    queue<Vertex> q;
    q.push(start);

    while(!q.empty()) {
        int time = get<TIME>(q.front());
        int y = get<Y>(q.front());
        int x = get<X>(q.front());
        unsigned long bought = get<BOUGHT>(q.front());
        q.pop();

        if(time > 100) break;
        int cost = sum(bought);
        if(memo[time][y][x][bought] >= cost) continue;
        memo[time][y][x][bought] = cost;
        result = max(result, cost);

        for(int i = 0; i < 4; ++i) {
            int ny = y + DY[i];
            int nx = x + DX[i];
            if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if(m[ny][nx] == NONE) continue;
            if(bought & (1 << m[ny][nx])) continue;
            for(int i = 0; i < n; ++i) {
                if(get<GOODS>(sale[i]) != m[ny][nx]) continue;
                if(time < get<START>(sale[i]) || get<END>(sale[i]) <= time) continue;
                bought |= 1 << i;
            }
        }

        time += 1;
        for(int i = 0; i < 4; ++i) {
            int ny = y + DY[i];
            int nx = x + DX[i];
            if(ny < 0 || h <= ny || nx < 0 || w <= nx) continue;
            if(m[ny][nx] != NONE) continue;
            q.push(Vertex(time, ny, nx, bought));
        }
    }

    return result;
}

int main() {
    while(cin >> w >> h, w | h) {
        Vertex start;
        m = vector<vector<int>>(h, vector<int>(w, NONE));
        for(int i = 0; i < h; ++i) for(int j = 0; j < w; ++j) {
            char c;
            cin >> c;
            if(c == '.') continue;
            else if(c == 'P') start = Vertex(0, i, j, 0);
            else m[i][j] = c - '0';
        }

        sale.clear();
        cin >> n;
        for(int i = 0; i < n; ++i) {
            int g, d, s, e;
            cin >> g >> d >> s >> e;
            sale.push_back(Sale(g, d, s, e));
        }

        cout << bfs(start) << endl;
    }
}

Measured memory_bytes: 45808
import bisect,collections,copy,itertools,math,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def SI(): return list(input().split())
##################################################
def main(N,bfrv):
    ans = [[[0]*10 for _ in range(3)] for _ in range(4)]
    for x in bfrv:
        b,f,r,v = x[0],x[1],x[2],x[3]
        ans[b-1][f-1][r-1] += v
    for i,x in enumerate(ans):
        if i:
            print('#'*20)
        for y in x:
            print(' ',end='')
            print(*y)
    
N = I()
bfrv = [LI() for _ in range(N)]
main(N,bfrv)


Measured memory_bytes: 6824
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int a = scan.nextInt();
		int b = scan.nextInt();
		int d = a / b;
		int r = a % b;
		double f = (double) a / (double) b;
		System.out.printf("%d %d %f\n", d, r, f);
	}
}

Measured memory_bytes: 26468
#include <stdio.h>
int main()
{
    int max500, max100, max50, num500 = 0, num100, remain, goal, ans = 0;
    scanf("%d", &max500);
    scanf("%d", &max100);
    scanf("%d", &max50);
    scanf("%d", &goal);

    for (; num500 <= max500; num500++)
    {
        remain = goal - 500 * num500;
        if (remain < 0)
            break;
        remain += 100;
        for (num100 = 0; num100 <= max100; num100++)
        {
            remain -= 100;
            if (remain < 0)
                break;
            if (remain <= max50 * 50) 
                ans++;
        }
    }

    printf("%d", ans);
    return 0;
}

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

using namespace std;
const int N = 2e5+5;
vector<int> v[N];
long long sum[N];
void dfs(int x, int u)
{
    sum[x]+=sum[u];
    for (auto it: v[x])
        if (it!=u)
            dfs(it,x);
}
int main()
{
    int n,q;
    cin >> n >> q;
    for (int i = 1; i<n; i++)
    {
        int x,y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for (int i = 1; i<=q; i++)
    {
        long long x,c;
        cin >> x >> c;
        sum[x]+=c;
    }
    dfs(1,0);
    for (int i = 1; i<=n; i++)
        cout << sum[i] << " ";
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

// 二次元累積和
struct cumulative_sum_2d {
    using lint = long long;
    int x, y;
    vector<vector<lint>> data;
    vector<vector<lint>> sum;
    cumulative_sum_2d(const int _x, const int _y) : x(_x), y(_y) {
        data.assign(x, vector<lint>(y, 0));
        sum.assign(x + 1, vector<lint>(y + 1, 0));
    }
    vector<lint> &operator[](const int k) {
        return data[k];
    }
    void build() {
        for (int i = 0; i < x; i++)
            for (int j = 0; j < y; j++)
                sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + data[i][j];
    }
    //[a,b)×[c,d)の和を計算
    lint query(const int a, const int b, const int c, const int d) const {
        return sum[b][d] - sum[b][c] - sum[a][d] + sum[a][c];
    }
};

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

int n, k;

int main() {
    cin >> n >> k;
    cumulative_sum_2d black(2 * k, 2 * k);
    for (int i = 0; i < n; i++) {
        int x, y;
        char c;
        cin >> x >> y >> c;
        if (c == 'W') {
            y += k;
        }
        x %= 2 * k, y %= 2 * k;
        black[x][y]++;
    }
    black.build();
    int ans = 0;
    for (int i = 0; i < k; i++) {
        for (int j = 0; j < k; j++) {
            int b_ok = black.query(0, i, 0, j) + black.query(i + k, 2 * k, 0, j) +
                       black.query(i, i + k, j, j + k) + black.query(0, i, j + k, 2 * k) +
                       black.query(i + k, 2 * k, j + k, 2 * k);
            chmax(ans, max(b_ok, n - b_ok));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=0x3f3f3f3f;
const int mod=998244353;
#define rep(i,x,y) for(auto i=(x);i<=(y);++i)
#define dep(i,x,y) for(auto i=(x);i>=(y);--i)
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int main(){
    int x=read(),y=read(),z=read();
    int ok=0;
    for(int i=y;i<=z;i++){
        if(i%x==0) ok=1;
    }
    if(ok) cout<<"OK";
    else cout<<"NG";
    return 0;
}

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

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  int n, t;
  scanf("%d%d",&n,&t);
  vll data(n), SUMR(n, 0);
  REP(i, n){
    scanf("%lld",&data[i]);
  }
  SUMR[n-1] = data[n -1];
  for(int i = n - 2;i >=0;i--){
    SUMR.at(i) = MAX(SUMR.at(i + 1), data.at(i));
  }
  /*
  for(int i = 0; i < n;i++){
    printf("%d : data = %d, SUMR = %d, Profit = %d\n", i, data[i], SUMR[i], data[i] - SUMR[i]);
  }*/

  int maxNum = 0;
  ll maxN = 0;
  for(int i = 0;i < n - 1;i++){
    ll tmp = SUMR[i] - data[i];
    if(maxN < tmp){
      maxN = tmp;
      maxNum = 1;

    }
    else if(maxN == tmp){
      maxNum++;
    }
  }
  cout << maxNum << "\n";
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int                 long long   
#define double              long double
#define endl                "\n"
#define pb                  push_back
#define PI                  3.1415926535897932384626433832795l
#define F                   first
#define S                   second
#define mp                  make_pair
#define f(i,n)              for(int i=0;i<n;i++)
#define fastio              ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)              (v).begin(),(v).end()
#define rall(v)             (v).rbegin(),(v).rend()
#define gcd(a,b)            __gcd((a),(b))
#define fill(a,value)       memset(a,value,sizeof(a));
#define minn(v)             *min_element(v.begin(), v.end());
#define maxx(v)             *max_element(v.begin(), v.end());
#define print(x)            cout<<(x)<<endl;
#define sum(v)+x            accumulate(v.begin(), v.end(),x);
#define debug(x)            cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int> pii;  
typedef vector<int> vi;

signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int a,b,n;
    cin>>a>>b>>n;
    if((b-1)<=n)
    {
        print((a*(b-1))/b)
    }
    else
    {
        print((a*(n))/b)
    }
    

    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define EM 100000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
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, A, B;
	cin >> N >> A >> B;
	cout << min(N*A, B) << endl;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P	  = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll g[200][200];
ll d[200][200];

double dif(P a, P b){
	double x = pow(a.first - b.first, 2) + pow(a.second - b.second, 2);
	return sqrt(x);
}

int main() {
	IOS();
	int n;
	cin >> n;
	vector<P> p(n);
	vector<int> perm(n);
	for (int i = 0; i < n;i++) {
		perm[i] = i;
	}
	for (int i = 0; i < n;i++) {
		cin >> p[i].first >> p[i].second;
	}
	double sum = 0;
	do {
		for (int i = 0; i < n  -1;i++) {
			sum += dif(p[perm[i]], p[perm[i + 1]]);
		}
	}while(next_permutation(perm.begin(), perm.end()));
	for (int i = 1; i <= n;i++) {
		sum /= i;
	}
	dumpf(sum, 7);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int const nmax = 200000;
int v[1 + nmax];
int canmove[1 + nmax];
int sum[1 + nmax];

int main()
{
  int n , result = 0;
  cin>>n;
  for(int i = 1 ; i <= n ;i++){
    cin>>v[i];
    if(v[i] == i){
      canmove[i] = 1;
    }
  }
  for(int i = n ;0 < i ;i--){
    if(canmove[i] == 1){
      sum[i] = sum[i + 1] + 1;
    } else{
      sum[i] = 0;
    }
  }
  /*
  for(int i = 1 ; i <= n ;i++){
    cout<<i<<" ";
  }
  cout<<'\n';
  for(int i = 1 ; i <= n ;i++){
    cout<<sum[i]<<" ";
  }
  cout<<'\n';
  //*/
  int pos = 1;
  while(pos <= n){
    //cout<<result<<" "<<pos<<" "<<sum[pos]<<" "<<sum[pos + 1]<<'\n';
    if(sum[pos] == 0){
      if(0 < sum[pos + 1]){
        result += sum[pos + 1] / 2 + sum[pos + 1] % 2;
        pos = pos + 1 + sum[pos + 1];
        //cout<<":"<<sum[pos + 1] / 2 + sum[pos + 1] % 2<<":";
      } else{
        pos++;
      }
    } else{
      if(sum[pos] % 2 == 0){
        result += sum[pos] / 2;
        pos = pos + sum[pos];
      } else{
        result += sum[pos] / 2 + sum[pos] % 2;;
        pos = pos + sum[pos] + 1;
      }
    }
  }
  cout<<result;
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
int main()
{
    int x,cnt=0,cnt1=0,cnt2=0,cnt3=0;
    char str1[]="AC",str3[]="TLE",str2[]="WA",str4[]="RE";
    char ch[5];
    scanf("%d%*c",&x);
    while(x--)
    {
        gets(ch);
        if(strcmp(str1,ch)==0)cnt++;
        else if(strcmp(str2,ch)==0)cnt1++;
        else if(strcmp(str3,ch)==0)cnt2++;
        else if(strcmp(str4,ch)==0)cnt3++;
    }
    printf("AC x %d\n",cnt);
    printf("WA x %d\n",cnt1);
    printf("TLE x %d\n",cnt2);
    printf("RE x %d\n",cnt3);
    return 0;

}


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

    for(i=0;i<n;i++)
    {
        if(v[i]!=v[i+1])
        {
            cont++;
        }
    }
    cout<<cont<<endl;

    return 0;
}


Measured memory_bytes: 11580
#include <stdio.h>

int main(void) {
	char s[100];
	int i=1;
	scanf("%s",s);
	for(;;){
		if(s[i-1]=='\0')break;
		if(i%2==0){
			if(s[i-1]=='R'){printf("No");return 0;}
		}else{
			if(s[i-1]=='L'){printf("No");return 0;}
		}
		i++;
	}
	printf("Yes");
	// your code goes here
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"

#define int long long

using namespace std;
#define REP(i, s, n) for(signed i = (s); i < signed(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for(int i = signed(n) - 1; i >= 0; i--)
#define all(co) co.begin(), co.end()

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

#ifdef int
const long long INF = 1ll << 62ll;
#else
const singed INF = 1 << 29;
#endif

struct edge{ int from, to, cost; };

int dr[] = { -1, 0, 1, 0 };
int dc[] = { 0, 1, 0, -1 };

template<typename T = int>
vector<vector<T>> vvector(int h, int w, T def = T()){ return move(vector<vector<T>>(h, vector<T>(w, def))); }

const int MAX_SIZE = 200001;
int BIT[MAX_SIZE];
int BIT_N;

void add(int i, int x)
{
	while (i <= BIT_N)
	{
		BIT[i] += x;
		i += i & -i;
	}
}

int sum(int i)
{
	int s = 0;
	while (i > 0)
	{
		s += BIT[i];
		i -= i & -i;
	}
	return s;
}

signed main()
{
	int n;
	while (cin >> n && n)
	{
		typedef pair<P, P> PP;
		vector<PP> lines;
		set<int> points;
		rep(i, n)
		{
			int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
			if (y1 > y2) swap(y1, y2);
			if(y1 == y2) lines.push_back(PP(P(y1, 1), P(x1, x2)));
			else
			{
				lines.push_back(PP(P(y1, 0), P(x1, x2)));
				lines.push_back(PP(P(y2, 2), P(x1, x2)));
			}
			points.insert(x1);
			points.insert(x2);
		}
		map<int, int> table;
		int idx = 1;
		for (int x : points)
		{
			table[x] = idx;
			idx++;
		}
		BIT_N = table.size();
		sort(all(lines));

		int ans = 0;
		vector<int> tate(table.size() + 1);
		for (PP pp : lines)
		{
			int y1 = pp.first.first, option = pp.first.second,
				x1 = table[pp.second.first], x2 = table[pp.second.second];
			if (x1 > x2) swap(x1, x2);

			if (option == 0) add(x1, 1);
			if (option == 2) add(x1, -1);
			if (option == 1) ans += sum(x2) - sum(x1 - 1);
		}

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

Measured memory_bytes: 15744
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};
use std::collections::HashMap;

fn main() {
    input!{
        n: usize,
        v: [(i64, i64); n]
    }
    let d = 1000000007;
    let mut map = HashMap::new();
    let mut zero = 0;
    for &xy in &v {
        let mut x = xy.0;
        let mut y = xy.1;
        if x == 0 && y == 0 {
            zero += 1;
            continue;
        }
        if x == 0 && y < 0 || x < 0 {
            x = -x;
            y = -y;
        }
        let g = gcd(x as usize, y.abs() as usize) as i64;
        x /= g;
        y /= g;
        if y > 0 {
            map.entry((x, y)).or_insert((0, 0)).0 += 1;
        } else {
            map.entry((-y, x)).or_insert((0, 0)).1 += 1;
        }
    }
    let mut ans = 1;
    for &(a, b) in map.values() {
        ans = ans * (pow_m(2, a, d) + pow_m(2, b, d) - 1) % d;
    }
    println!("{}", (ans + zero + d - 1) % d);
}

fn pow_m(n: usize, mut p: usize, d: usize) -> usize {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % d;
            p /= 2;
        } else {
            ret = ret * r % d;
            p -= 1;
        }
    }
    ret
}

fn gcd(n: usize, m: usize) -> usize {
    let mut l = min(n, m);
    let mut r = max(n, m);
    while l > 0 {
        let t = l;
        l = r % l;
        r = t;
    }
    r
}


Measured memory_bytes: 18012
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  vector<pair<int,int>> br(M);
  for(int i = 0;i < M;i++) {
    cin >> br.at(i).second >> br.at(i).first;
  }

  
  sort(br.begin(),br.end());
  int ans = 1,e = br.at(0).first;
  for(int i = 1;i < M;i++) {
    if(br.at(i).second >= e) {
      ans++;
      e = br.at(i).first;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
using ll = long long;
using P = pair<int, int>;

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

  int n,k;
  cin >> n >> k;
  vector< vector<int> > as(k);
  for (auto & v : as) {
    int d;
    cin >> d;
    v = vector<int>(d);
    for (auto & e : v) cin >> e;
  }

  vector<int> snk(n, 0);
  for (const auto v : as) for (const auto x : v) ++snk[x - 1];
  int count = 0;
  for (const auto s : snk) count += s == 0 ? 1 : 0;
  cout << count << endl;

}

Measured memory_bytes: 3664
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int a,b;
    
    cin >> a >>b;
    
    if (a>8 || b>8){
    
    cout << ":(" << endl;
    
    
    }else{
    
    cout << "Yay!" << endl;
    
    }
    
    
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int N, x[3], y[3]; std::cin >> N;
  for(int i = 0; i < 3; ++i) std::cin >> x[i];
  for(int i = 0; i < 3; ++i) std::cin >> y[i];
  std::vector<int> w, v;

  int64_t const INF = 1e18;
  auto trade = [&](int64_t n)->int64_t {
    auto dp = mk2d(w.size()+1, n+1, -INF);
    std::fill_n(dp[0].begin(), n+1, 0);
    for(int i = 0; i < w.size(); ++i) {
      // don't use i-th
      std::copy_n(dp[i].begin(), n+1, dp[i+1].begin());
      // use i-th
      for(int j = w[i]; j <= n; ++j) {
        dp[i+1][j] = std::max(dp[i+1][j], dp[i+1][j-w[i]] + v[i]);
      }
    }
    return n+dp[w.size()][n];
  };

  for(int i = 0; i < 3; ++i) if(x[i] < y[i]) {
    w.push_back(x[i]);
    v.push_back(y[i]-x[i]);
  }
  int64_t ans = trade(N);
  w.clear(); v.clear();
  for(int i = 0; i < 3; ++i) if(x[i] > y[i]) {
    w.push_back(y[i]);
    v.push_back(x[i]-y[i]);
  }
  fin(trade(ans));
  return 0;
}


Measured memory_bytes: 773632
import sys
import numpy as np
import math
import random
from decimal import Decimal
import itertools
import re
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(2147483647)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

def main():
	a, b = LS()
	ad = Decimal(a)
	bd = Decimal(b)
	product = ad * bd
	print(int(product))




if __name__ == '__main__':
    main()

Measured memory_bytes: 27252
import math
MOD = 10**9+7
n,m = map(int,input().split())
#大きい順に並べる
if n < m:
  n,m = m,n

# mがn-1より小さいとどこかで犬・サル同士が隣り合う
if n-1 > m:
  print(0)
  exit()
  
if n == m:
  ans = math.factorial(n)* math.factorial(m)*2
  print(ans%MOD)
  
elif n-1 == m:
  ans = math.factorial(n)* math.factorial(m)
  print(ans%MOD)
    
  

Measured memory_bytes: 5184
#include <iostream>
#include <vector>
#include <algorithm>
 
int main(){
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for(int i = 0 ; i < n ; i ++){
    std::cin >> v[i];
  }
  std::vector<int> tmp= v;
  std::sort(v.begin(),v.end());
  for(int i = 0 ; i < n ; i++){
    if(v[n-1]==tmp[i]) std::cout << v[n-2]<<std::endl;
    else std::cout << v[n-1]<<std::endl;
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) > (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define R cin>>
#define repr(i, n) REPR(i, n, 0)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define in(a) insert(a)
#define P(p) cout<<(p)<<endl;
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SORT(a) sort((a).begin(), (a).end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long int> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;
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;}
template<typename T> void co(T e){cout << e << "\n";}
template<typename T> void co(const vector<T>& v){for(const auto& e : v)
    { cout << e << " "; } cout << "\n";}
ll gcd(ll a, ll b) {
    if (a < b)swap(a, b);
    if (b == 0) return a;
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}
ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a * b / g;
}
bool prime(ll n) {
    for (ll i = 2; i <= sqrt(n); i++) {
        if (n%i == 0)return false;
    }
    return n != 1;
}

Vec fac, finv;

ll PowMod(ll a, ll n){
    if(n == 1) return a;
    if(n%2 == 0) return PowMod(a*a%MOD, n/2);
    return a*PowMod(a*a%MOD, n/2)%MOD;
}

ll combi(ll n, ll k){
    if(k>n) return 0;
    return fac[n]*finv[k]%MOD*finv[n-k]%MOD;
}

int main(){
    int a, b;
    R a >> b;
    if(b % a){
        co(b - a);
    }else{
        co(a + b);
    }
}


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

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

using namespace std;

typedef long long ll;

const long long N = (long long) 1e6 + 5;
const long long mod = (long long) 1e9 + 7;

long long n,a[N],ans = 1,pr[N],dp[N];

int main(){
        cin >> n;

        for(long long i = 1; i <= n; i ++)
                cin >> a[i];

        sort(a + 1,a + n + 1);

        for(long long i = 1; i <= n; i ++)
                pr[i] = pr[i - 1] + a[i];

        dp[n] = 1;
        for(long long i = n - 1; i >= 1; i --){
                if(a[i + 1] <= pr[i] * 2 && dp[i + 1] == 1)
                        dp[i] = 1,ans ++;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
using namespace std;
int n, s, t; int dp[16][65536], p[16][16];
queue<pair<int, int>>Q;
int main() {
	while (true) {
		cin >> n; s = 0; t = 0; if (n == 0)break;
		for (int i = 0; i < n; i++) { for (int j = 0; j < (1 << n); j++)dp[i][j] = 999999999; }
		string S1; cin >> S1; for (int i = 0; i < S1.size(); i++) { if (S1[i] == 'B')s += (1 << i); }
		string S2; cin >> S2; for (int i = 0; i < S2.size(); i++) { if (S2[i] == 'B')t += (1 << i); }
		for (int i = 0; i < n; i++) { dp[i][s] = 0; Q.push(make_pair(i, s)); }
		while (!Q.empty()) {
			int a1 = Q.front().first, a2 = Q.front().second; Q.pop();
			if (a1 < n - 1 && dp[a1 + 1][a2] > dp[a1][a2] + 1) { dp[a1 + 1][a2] = dp[a1][a2] + 1; Q.push(make_pair(a1 + 1, a2)); }
			if (a1 >= 1 && dp[a1 - 1][a2] > dp[a1][a2] + 1) { dp[a1 - 1][a2] = dp[a1][a2] + 1; Q.push(make_pair(a1 - 1, a2)); }
			for (int i = 0; i < n; i++) {
				int bit[20]; for (int j = 0; j < n; j++)bit[j] = (a2 / (1 << j)) % 2;
				swap(bit[i], bit[a1]); int cost = abs(i - a1);
				int ret = 0; for (int j = 0; j < n; j++)ret += (1 << j)*bit[j];
				if (dp[i][ret] > dp[a1][a2] + cost) { dp[i][ret] = dp[a1][a2] + cost; Q.push(make_pair(i, ret)); }
			}
		}
		int minx = 999999999; for (int i = 0; i < n; i++)minx = min(minx, dp[i][t]);
		cout << minx << endl;
	}
	return 0;
}

Measured memory_bytes: 7584
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const int MAXN = 100007;
const LD EPS = 1e-7;

int n, A[MAXN];

bool possible()
{
	LL s = 0, c;
	REP(i, n) s += A[i];
	if ((2 * s) % (n * (n + 1LL))) return false;
	c = (2 * s) / (n * (n + 1LL));
	REP(i, n)
	{
		if (c + A[i] - A[i + 1] < 0) return false;
		if ((c + A[i] - A[i + 1]) % n) return false;
	}
	return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	cin >> n;
	REP(i, n) cin >> A[i];
	A[n] = A[0];
	if (possible()) cout << "YES";
	else cout << "NO";
	//cout << endl; system("pause");
	return 0;
}

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

int main()
{
  	long n,a,mn,mx,sum;
  
 	cin >> n >> a;
  
  	mn = mx = sum = a;
  
 	for(int i = 0;i < n-1;i++){
      cin >> a;
      
      mn = min(mn,a);
      mx = max(mx,a);
      sum += a;
    }
      cout << mn << " " << mx << " " << sum << endl;
}


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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
void tostr(ll x,string& res){while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return;}
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; }
//template end



int main(){
   int n; scanf("%d",&n);
   printf("%d\n",(n+1)/2);
   return 0;
}

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

using namespace std;

typedef long long ll;

const int Mod = 1e9 + 7;

const int N = 200200;

int P[N];

void add_self(int& x, int y)
{
    if((x += y) >= Mod) x -= Mod;
}

int add(int x, int y)
{
    return add_self(x, y), x;
}

void sub_self(int& x, int y)
{
    if((x -= y) < 0)    x += Mod;
}

int sub(int x, int y)
{
    return sub_self(x, y), x;
}

int mul(int x, int y)
{
    return (ll) x * y % Mod;
}

ll GCD(ll x, ll y)
{
    return y ? GCD(y, x % y) : x;
}

pair <ll,ll> Bad(pair <ll,ll> p)
{
    p = make_pair(p.second, -p.first);

    if(p.first < 0 || (p.first == 0 && p.second < 0))
        p.first = -p.first, p.second = -p.second;

    return p;
}

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

    P[0] = 1;
    for(int i = 1; i < N; ++i)  P[i] = mul(2, P[i - 1]);

    int n;  cin >> n;

    vector <ll> A(n);
    vector <ll> B(n);

    int Zeros = 0;
    map <pair <ll,ll>, int> Cnt;

    for(int i = 0; i < n; i++)
    {
        scanf("%lld%lld", &A[i], &B[i]);

        if(!A[i] && !B[i])
        {
            Zeros++;
            continue;
        }

        ll G = GCD(A[i], B[i]);

        A[i] /= G;
        B[i] /= G;

        if(A[i] < 0 || (A[i] == 0 && B[i] < 0)) A[i] = -A[i], B[i] = -B[i];

        Cnt[make_pair(A[i], B[i])]++;
    }

    set <pair <ll,ll>> Have;

    vector <pair <int,int>> Friends;

    for(auto x : Cnt)
    {
        if(Have.count(x.first)) continue;

        pair <ll,ll> X = x.first;
        pair <ll,ll> Y = Bad(X);

        Have.insert(X);
        Have.insert(Y);

        Friends.emplace_back(Cnt[X], Cnt.count(Y) ? Cnt[Y] : 0);
    }

    int Ans = 1;

    for(pair <ll,ll> p : Friends)
    {
        int Res = sub(add(P[p.first], P[p.second]), 1);

        Ans = mul(Ans, Res);
    }

    sub_self(Ans, 1);
    add_self(Ans, Zeros);

    cout << Ans << endl;
}


Measured memory_bytes: 46180
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b > 9) cout << "error\n";
	else cout << a + b << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    A,B = map(int, lines.pop(0).split(' '))
    if B%A == 0:
        print(A+B)
    else:
        print(B-A)


#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

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

#define MAXN (1010)
#define mod (1000000007) 

int N, A, B, C, D;
int fact[MAXN], rfact[MAXN];
int dp[MAXN][MAXN];

int powmod(int a, int b){
	int ret = 1;
	while(b){
		if(b & 1) ret = (1ll) * ret * a % mod;
		b >>= 1;
		a = (1ll) * a * a % mod;
	}
	return ret;
}

int getA(int a, int b){
	return (1ll) * fact[a] * rfact[a - b] % mod;
}

int main(){
	fact[0] = rfact[0] = 1;
	for(int i = 1; i < MAXN; ++ i){
		fact[i] = (1ll) * fact[i - 1] * i % mod;
		rfact[i] = powmod(fact[i], mod - 2);
	}
	scanf("%d%d%d%d%d", &N, &A, &B, &C, &D);
	
	dp[A - 1][0] = 1;
	for(int i = A; i <= B; ++ i){
		//k = 0
		for(int j = 0; j <= N; ++ j){
			dp[i][j] = dp[i - 1][j];
		}
		
		for(int k = C; k <= D && i * k <= N; ++ k){
			for(int j = i * k; j <= N; ++ j){
				dp[i][j] = (dp[i][j] + 
				(1ll) * dp[i - 1][j - i * k] * getA(j, i * k) % mod *
				rfact[k] % mod * powmod(rfact[i], k) % mod) % mod;
			}
		}
	}
	
	printf("%d\n", dp[B][N]);
	return 0;
}

Measured memory_bytes: 4224