akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void){
	int acnt,bcnt,i,len;
	char str[101];
	while(1){
		acnt=0; bcnt=0;
		cin>>str;
		if(str[0]=='0') break;
		len=strlen(str);
		for(i=1;i<len;i++){
			if(str[i]=='A') acnt++;
			if(str[i]=='B') bcnt++;
		}
		if(acnt>bcnt) acnt++;
		if(acnt<bcnt) bcnt++;
		cout<<acnt<<' '<<bcnt<<endl;
	}
	return 0;
}

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

#define F first 
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
LL l, r;

int main()
{
	cin >> n;
	l = r = 1LL;
	
	while (n -- )
	{
		LL a, b;
		cin >> a >> b;
		
		LL t1 = (l + a - 1LL) / a;
		LL t2 = (r + b - 1LL) / b;
		LL t = max(t1, t2);
		
		l = t * a;
		r = t * b;
	}
	
	cout << l + r << endl;
    return 0;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e2 + 5);

int h, w;

char a[MAX_N][MAX_N];

unordered_map<int, int> count() {
  unordered_map<char, int> cnt;

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cnt[a[i][j]] += 1;
    }
  }

  unordered_map<int, int> ret;

  for (auto &e : cnt) {
    ret[e.second % 4] += 1;
  }

  return ret;
}

int main(void) {
  // Here your code !
  scanf("%d %d", &h, &w);

  for (int i = 0; i < h; ++i) {
    scanf("%s", &(a[i]));
  }

  auto cnt = count();

  string ans = "No";

  if (h % 2 == 0 && w % 2 == 0) {
    if (cnt[3] == 0 && cnt[2] == 0 && cnt[1] == 0) ans = "Yes";
  } else if (h % 2 == 1 && w % 2 == 1) {
    if (cnt[3] == 0 && (cnt[2] * 2 <= (h + w - 2)) && cnt[1] == 1) ans = "Yes";
  } else {  // (1, 0) or (0, 1)
    int even = (h % 2 == 0) ? h : w;
    if (cnt[3] == 0 && cnt[2] * 2 <= even && cnt[1] == 0) ans = "Yes";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    int cnt = 1;
    int next = -1;
    cin >> n;
    for(int i = 1; i <= 4; i++) {

        if ((n % 10) == next) {
            cnt++;
            if(cnt == 3) {
                cout << "Yes";
                return 0;
            }
        } else {
            cnt =1;
            next = n % 10;
        }
        n /= 10;
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
import sys
import heapq
heappush = heapq.heappush
heappop = heapq.heappop
heapreplace = heapq.heapreplace
input = sys.stdin.readline

D = int(input())
cost = list(map(int, input().strip().split()))
S = [list(map(int, input().strip().split())) for _ in range(D)]
k = 2
last_held = [[-1 for i in range(26)] for _ in range(k)]
ans = [[] for _ in range(k)]
for date, daily_scores in enumerate(S):
    max_score = []
    for state in range(k):
        minus_score = 0
        for i in range(26):
            minus_score += cost[i] * (date - last_held[state][i])

        for i in range(k-len(max_score)):
            tmp = daily_scores[i] + cost[i] * (date - last_held[state][i])
            heappush(max_score, (tmp, i, state))

        for i, daily_score in enumerate(daily_scores):
            if i < k:
                continue
            tmp = daily_score + cost[i] * (date - last_held[state][i])
            if max_score[0][0] < tmp:
                heapreplace(max_score, (tmp, i, state))
    if date != D-1:
        next_last_held = []
        next_ans = []
        for score, i, state in max_score:
            next_last_held.append(last_held[state][:])
            next_last_held[-1][i] = date
            next_ans.append(ans[state][:])
            next_ans[-1].append(i+1)
        ans = next_ans
        last_held = next_last_held
    else:
        score, i, state = max(max_score)
        next_ans = ans[state][:]
        next_ans.append(i+1)
        ans = next_ans

print("\n".join(map(str, ans)))


Measured memory_bytes: 69160
# x = list(map(int, input().split()))   :  int の リスト入力
# x, y = map(int, input().split())      :  それぞれの変数に　int 入力
# z = set(map(int, input().split()))    :
# t = int(input())                      :   

s = str(input())
t = str(input())
ans=0
l = len(s)
for i in (range(l)):
    if s[i]!=t[i]:
        ans += 1
print(ans)

Measured memory_bytes: 67996
#include<stdio.h>
int main(void){
	int sum,c,d;
	scanf("%d %d %d",&c,&d,&sum);
	if(sum-c<0){
	printf("NO");
	return 0;
	}
	if(sum-c>d){
	printf("NO");
	return 0;
	}
	if(sum-c<d){
  printf("YES");
	return 0;
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (1000000007)

int n, L, x[6000], a[6000];
int dp[6000], s[6000];

int main() {
    scanf("%d%d", &n, &L);
    rep (i, n) scanf("%d", x+i);
    rep (i, n) scanf("%d", a+i);
    dp[L] = 1;
    for (int k = n-1; k >= 0; k--) {
        for (int i = L; i >= 0; i--) {
            s[i] = (s[i+1] + dp[i]) % MOD;
            if (a[k] == 0) {
                if (i == x[k]) dp[i] = s[i+1];
                else dp[i] = 0;
            }
            else {
                if (i >= x[k] && (i - x[k]) % a[k] == 0) dp[i] = s[i+1];
                else dp[i] = 0;
            }
        }
    }
    int ans = 0;
    rep (i, L) ans = (ans + dp[i]) % MOD;
    printf("%d\n", (int)ans);
    return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>
#include <cctype>
#include <cmath>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100000;
const int MOD = 1000000007;
const int NIL = -1;
const double pi = 3.141592653589;
/* global variables */
struct Node {
    int parent,  // parent
        left,    // left child
        right;   // right sibling
};
struct Node T[MAX];
vector<int> Depth(MAX, 0);
vector<int> Height(MAX, 0);

/* function */
int getDepth(int u);
int getSibling(int u);
void setDepth(int u, int p);
void setHeight(int u);
int printChildlen(int u);
void printNodeType(int t);
void printAns(int u);

/* main */
int main(){

    int n, v, l, r;
    cin >> n;
    for (int i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = NIL;
    }

    for (int i = 0; i < n; i++) {
        cin >> v >> l >> r;
        if (l != NIL) {
            T[v].left = l;
            T[l].parent = v;
        }
        if (r != NIL) {
            T[v].right = r;
            T[r].parent = v;
        }
    }

    int root;
    for (int i = 0; i < n; i++) {
        if (T[i].parent == NIL) root = i;
        setHeight(i);
    }

    setDepth(root, 0);

    for (int i = 0; i < n; i++) {
        printAns(i);
    }

    return 0;
}

int getDepth(int u) {
    int d = 0;
    while (T[u].parent != NIL) {
        u = T[u].parent;
        d++;
    }
    return d;
}

int countChildlen(int u) {
    int cnt = 0;
    if (T[u].left != NIL)
        cnt++;
    if (T[u].right != NIL)
        cnt++;
    return cnt;
}

void setDepth(int u, int p) {
    Depth[u] = p;
    if (T[u].right != NIL) {
        setDepth(T[u].right, p + 1);
    }
    if (T[u].left != NIL) {
        setDepth(T[u].left, p + 1);
    }
}

void setHeight(int u) {
    int h = 0;
    while (u != NIL) {
        Height[u] = max(Height[u], h);
        h++;
        u = T[u].parent;
    }
}

void printNodeType(int t) {
    if (T[t].parent == NIL)
        cout << "root";
    else if (T[t].left == NIL && T[t].right == NIL)
        cout << "leaf";
    else
        cout << "internal node";
}

int getSibling(int u) {
    int p = T[u].parent;
    if (p == NIL) {
        return NIL;
    }
    if (T[p].left == u) {
        return T[p].right;
    }
    else {
        return T[p].left;
    }
}

void printAns(int u) {

    int p;
    cout << "node " << u << ": ";
    p = T[u].parent;
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    cout << "degree = " << countChildlen(u) << ", ";
    cout << "depth = " << Depth[u] << ", ";
    cout << "height = " << Height[u] << ", ";
    printNodeType(u);
    cout << '\n';

}



Measured memory_bytes: 3448
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

void Yes()
{
	OUT("Yes");
}
void No()
{
	OUT("No");
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

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

void Main()
{
	inll n, k;

	ll cnt = 0;

	//FOR(a, k, n + 1)
	//{
	//	cnt += (a - k) 
	//}

	FOR(b, k + 1, n + 1)
	{
		cnt += (b - k) * ((n + 1) / b);
		cnt += max((n + 1) % b - k, ll(0));
		//if (n % b > k)
		//	cnt += n % b - k;
	}
	if (k == 0)
		cnt -= n;
	//FOR(a, 1, n + 1)
	//{
	//	FOR(b, 1, n + 1)
	//	{
	//		//cnt += (a / b) * (b - k);
	//		if (a % b >= k)
	//			cnt++;
	//	}
	//}

	return OUT(cnt);
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
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 = 10 ** 9 + 7



class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n


    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]


    def is_same(self, x, y):
        return self.root(x) == self.root(y)


    def union(self, x, y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2


n, m = LI()
U = UnionFind(n)
for i in range(m):
    x, y, z = LI()
    U.union(x - 1, y - 1)



print(len(set([U.root(j) for j in range(n)])))



Measured memory_bytes: 78296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 2e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

ll cnt[100010];

int main() {
    int n, m;
    cin >> n >> m;
    int a[m];
    bool ok[n + 1];
    rep(i, 0, n + 1) ok[i] = true;
    rep(i, 0, m) {
        cin >> a[i];
        ok[a[i]] = false;
    }

    cnt[0] = 1;
    if (ok[1]) cnt[1] = 1;
    rep(i, 2, n + 1) {
        if (ok[i] && ok[i - 1]) cnt[i] += cnt[i - 1];
        if (ok[i] && ok[i - 2]) cnt[i] += cnt[i - 2];
        cnt[i] %= MOD;
    }
    cout << cnt[n] << endl;
    return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c;
	double C, s, l, h;
	cin >> a >> b >> c;
	C = c * 3.1415926535897932384626433;
	C = C / 180;
	s = a * b*sin(C) / 2;
	h = b * sin(C);
	l = a * a + b * b-2 * a*b*cos(C);
	l = sqrt(l);
	l = l + a + b;
	cout << fixed;
	cout << setprecision(13) << s << endl;
	cout << setprecision(13) << l << endl;
	cout << setprecision(13) << h << endl;
	return 0;
}


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define up(i,j,n) for( int i=j;i<=n;i++)
#define down(i,j,n) for( int i=j;i>=n;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define FILE "dealing"
#define ull unsigned int
int read(){
	int x=0,ch=getchar(),f=1;
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}

template<class T> bool cmin(T& a,T b){return a>b?a=b,true:false;}
template<class T> bool cmax(T& a,T b){return a<b?a=b,true:false;}
template<class T> T squ(T a){return a*a;}
const int maxn=405000,inf=1000000000,limit=100000,mod=1e9+7;
int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
int sub(int a,int b){return (a-=b)<   0?a+mod:a;}
int mul(int a,int b){return 1LL*a*b%mod;}
int n;
int q[maxn],head,tail;

int main(){
	//freopen(FILE".in","r",stdin);freopen(FILE".out","w",stdout);
	int now=0;
	n=read();
	head=n,tail=n-1;
	up(i,1,n){
		if(!now)q[++tail]=read();
		else q[--head]=read();
		now^=1;
	}
	if(!now)up(i,head,tail)printf("%d%c",q[i],i==tail?'\n':' ');
	else for(int i=tail;i>=head;i--)printf("%d%c",q[i],i==head?'\n':' ');
	return 0;
}





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

int main() {
  int N, A;
  cin >> N >> A;
  
  if (N % 2 == 0 || A % 2 == 0) {
    cout << "Even" << endl;
  }
  else cout << "Odd" << endl;
  
  // ここにプログラムを追記
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CVacation solver = new CVacation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CVacation {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {


            int n = in.scanInt();
            long arr[][] = new long[n][3];
            for (int i = 0; i < n; i++) {
                arr[i][0] = in.scanInt();
                arr[i][1] = in.scanInt();
                arr[i][2] = in.scanInt();
            }

            long dp[][] = new long[n][3];
            for (long ar[] : dp) Arrays.fill(ar, Long.MIN_VALUE);
            dp[0][0] = arr[0][0];
            dp[0][1] = arr[0][1];
            dp[0][2] = arr[0][2];

            for (int i = 1; i < n; i++) {
                for (int k = 0; k < 3; k++) {
                    for (int j = 0; j < 3; j++) {
                        if (k == j) continue;
                        dp[i][k] = Math.max(dp[i - 1][j] + arr[i][k], dp[i][k]);
                    }
                }
            }
            out.println(Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])));
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    string S = "Alice";
    if ((B - A - 1) % 2 == 0)
        S = "Borys";
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

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

int main() {
	int N;
	cin>>N;
	vector<ll> A(N);
	ll summ = 0;
	rep(i,N){
		cin>>A[i];
		summ += A[i];
	}
	vector<ll> Mt(N);
	for (int i = 0; i < N; i++){
		if(i%2 == 0)continue;
		summ-=2*A[i];
	}
	Mt[0] = summ;
	rep(i,N-1){
		Mt[i+1] = 2*A[i] - Mt[i];
	}
	rep(i,N){
		if(i==N-1){
			cout<<Mt[i]<<endl;
			return 0;
		}
		cout<<Mt[i]<<" ";
	}
}

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

int main(){
	long long int  n,m;
	cin>>n>>m;
	
	if((long long)(2*n)>m) cout<<m/2;
	if((long long)(2*n)<m) cout<<n+(m-2*n)/4;
	if((long long)(2*n)==m) cout<<n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define isSquare(x) (sqrt(x)*sqrt(x) == x)
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
const int MOD = 1e9 + 7;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}//mod mでの逆元aを計算

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

struct combination{
    long long mod = MOD;
    vector<long long> fact, ifact;
    combination(int n, const long long tmp = MOD):fact(n+1), ifact(n + 1){
        mod = tmp;
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i % mod;
        ifact[n] = modpow(fact[n], mod - 2, mod);
        for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i % mod;
    }
    long long C(int n, int k){
        if(k < 0 || k > n) return 0;
        return fact[n]*ifact[k]%mod*ifact[n-k] % mod;
    }
};


int main(){
    iosetup;
    int p; IN(p);
    combination C(p-1, p) ;
    vector<int> a(p);
    rep(i, 0, p) cin >> a[i];

    cout << a[0];
    rep(i, 1, p){
        ll ans = 0;
        rep(j, 0, p) if(a[j] == 1){
            if(((p-1-i)&1) == 0) ans -=(C.C(p-1, i) * modpow(j,p-1-i, p));
            else ans +=C.C(p-1, i) * modpow(j, p-1-i, p);
        }
        // cerr << ans << endl;
        ans %= p;
        if(ans < 0) ans += p;
        cout << " ";
        cout << ans;
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 384
package main

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

func intSlice(str string) []int {
	splitted := strings.Split(str, " ")
	ret := make([]int, len(splitted))

	for i, str := range splitted {
		if strings.TrimSpace(str) != "" {
			n, _ := strconv.Atoi(str)
			ret[i] = n
		}
	}

	return ret
}

func main() {

	stdin := bufio.NewScanner(os.Stdin)

	// 一行目
	stdin.Scan()
	line1 := stdin.Text()
	ints1 := intSlice(line1)
	n := ints1[0]
	m := ints1[1]

	lMax := 0
	rMin := n

	// ゲートはm個
	for i := 0; i < m; i++ {
		stdin.Scan()
		line := stdin.Text()
		ints := intSlice(line)

		if lMax < ints[0] {
			lMax = ints[0]
		}
		if rMin > ints[1] {
			rMin = ints[1]
		}
	}

	if lMax > rMin {
		fmt.Println(0)
	} else {
		fmt.Println(rMin - lMax + 1)
	}
}


Measured memory_bytes: 5504
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a+b<10)cout<<a+b<<endl;
	else cout<<"error"<<endl;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000)

while(True):
    w,h = map(int,input().split())
    if w == 0 and h == 0:
        break
    c = [0] * h
    for i in range(h):
        c[i] = list(map(int,input().split()))

    checked = [[0] * w for _ in range(h)]
    def dfs(x,y):
        global checked,c
        checked[y][x] = 1
        c[y][x] = 0
        for i in range(-1,2):
            for j in range(-1,2):
                if 0 <= x + i < w and 0 <= y + j < h:
                    if checked[y + j][x + i] == 0 and c[y + j][x + i] == 1:
                        dfs(x + i,y + j)

    cnt = 0
    for i in range(h):
        for j in range(w):
            if c[i][j] == 1:
                dfs(j,i)
                cnt += 1

    print(cnt)


Measured memory_bytes: 8020
def sumOfDigits(a):
    sm = 0
    while(a!=0):
        sm = sm + a % 10
        a = a // 10
     
    return sm
     
# Returns the maximum number
# with maximum sum of digits.
def findMax(x) :
     
    # initializing b as 1
    # and initial max sum
    # to be of n
    b = 1
    ans = x
     
    # iterates from right
    # to left in a digit
    while (x!=0) :
        # while iterating this 
        # is the number from
        # right to left
        cur = (x - 1) * b + (b - 1)
         
        # calls the function to
        # check if sum of cur is
        # more then of ans
        if (sumOfDigits(cur) > sumOfDigits(ans) or
        (sumOfDigits(cur) == sumOfDigits(ans) and
            cur > ans)) :
                ans = cur
 
        # reduces the number
        # to one unit less
        x =x // 10
        b = b * 10
     
     
    return ans

def sum_digits(n):
    s = 0
    while n:
        s += n% 10
        n //= 10
    return s
# driver program to test the above function
n = int(input())
maxDigit = findMax(n)
print(sum_digits(maxDigit))


Measured memory_bytes: 3316
// In The Name Of Allah
// Mehrkish Makuei

#include <bits/stdc++.h>

#define pb push_back
#define debug1(x) cerr << #x << " : " << x << endl;
#define debug2(x, y ) cerr << #x << " : " << x << "  " << #y << " : " << y << endl;

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef vector <ll> vll;
typedef set <char> sch;
typedef set <ll> sll;

const ll MOD = 1e9 + 7;
const ll MAXN = 1e3 + 19;

str s;

int main(){
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> s;
	ll n = s.size();
	for ( int i = 0; i < n; i++ )
		if ( s[i] == ',' )
			s[i] = ' ';
	cout << s << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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;}

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl


int main(){
    int x,y,xx,yy;
    cin>>x>>y>>xx>>yy;
    xx-=x;
    yy-=y;
    REP(i,yy){
        cout<<'U';
    }
    REP(i,xx){
        cout<<'R';
    }
    REP(i,yy){
        cout<<'D';
    }
    REP(i,xx){
        cout<<'L';
    }
    cout<<'L';
    REP(i,yy+1){
        cout<<'U';
    }
    REP(i,xx+1){
        cout<<'R';
    }
    cout<<'D';

    cout<<'R';
    REP(i,yy+1){
        cout<<'D';
    }
    REP(i,xx+1){
        cout<<'L';
    }
    cout<<'U';
    cout<<endl;


    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
k = int(input())


def snuke(n):
    s = 0
    for _ in str(n):
        s += int(_)
    return n / s


n = 1
d = 0
for _ in range(k):
    print(n)
    if snuke(n + 10**d) > snuke(n + 10**(d + 1)):
        d += 1
    n += 10**d


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    vector<int> water;
    for(int i = 0; i <= 30; i++)
    {
        for(int j = 0; j <= 30; j++)
        {
            int temp = 100*a*i+100*b*j;
            if (temp <= f) {
                water.push_back(temp);
            }
        }
    }
    vector<int> suger;
    for(int i = 0; i <= f; i++)
    {
        for(int j = 0; j <= f; j++)
        {
            int temp = c*i + d*j;
            if (temp <= f) {
                suger.push_back(temp);
            }
        }
    }
    double co = 0;
    int answa = 0, anssu = 0;
    for(int wa : water){
        for(int su : suger){
            if (wa+su > 0 && wa+su <= f && su <= wa*e/100) {
                double tmp = (double) su/(wa+su);
                if (tmp >= co) {
                    co = tmp;
                    answa = wa+su;
                    anssu = su;
                }
            }
        }
    }
    cout << answa << " " << anssu << endl;
}

Measured memory_bytes: 1400
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

long long GCD (long long C, long long D) {
   while (1) {
      if (C == 0 || D == 0) break;
      if (D>C) D -= (D/C)*C;
      else C -= (C/D)*D;
   }
   return max(C,D);
}

long long LCM(long long C, long long D) {
   return C / GCD(C,D) * D;
}

int main(void) {
   ll N;
   cin>>N;
   vector<ll> A(N,0);
   rep(i,0,N) cin>>A[i];
   ll lcm = 1;
   rep(i,0,N) {
      lcm = LCM(lcm,A[i]);
   }
   cout<<lcm<<endl;


   return 0;
}

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

int main() {
    string s;
    cin >> s;
    int a = 1000000;
    int z = 0;
    int i = 0;
    for (auto c : s){
        if (c == 'A') a = min(a, i);
        if (c == 'Z') z = i;
        ++i;
    }
    cout << z - a + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T gcd(T u, T v) {
    ll r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T lcm(T u, T v) {
    return u * v / gcd(u, v);
}

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

    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    cin >> L;

    int ans = INF;
    int loop = (int)pow(2, N * 2);
    REP(i, loop) {
        int a = 0, b = 0, c = 0, mp = 0;
        REP(j, N) {
            int bit = i >> (j * 2) & 3;
            if (bit == 0) {
                if (a > 0)mp += 10;
                a += L[j];
            }
            else if (bit == 1) {
                if (b > 0)mp += 10;
                b += L[j];
            }
            else if (bit == 2) {
                if (c > 0)mp += 10;
                c += L[j];
            }
        }

        if (a == 0 || b == 0 || c == 0)continue;
        mp += abs(A - a);
        mp += abs(B - b);
        mp += abs(C - c);
        ans = min(ans, mp);
    }

    cout << ans << endl;
    return 0;

}

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

int main() {
  string s;
  cin >> s;
  
  long long result = 0;
  for (int i = 0; i < s.size()/2; i++) {
    if (s[i] != s[s.size() - 1 - i]) {
      result++;
    }
  }
  
  cout << result << endl;  
  return 0;
}

Measured memory_bytes: 256
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define INF_LL 1000000000000000000LL
#define INF 200000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m), c;
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    c = convolution<998244353>(a, b);
    rep(i, n + m - 1) cout << c[i] << " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 27228
#include<bits/stdc++.h>
#define MN 300000
using namespace std;
inline 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 n,a[MN+5],tot[2],ans,s[MN+5],L[MN+5],R[MN+5];
bool Solve(int lim)
{
    int mn=1e9;memset(L,0,sizeof(L));
    for(int j=2;j<=n;j+=2)
    {
        if(tot[0]+s[j-1]>=lim) L[j]=true;
        if(tot[0]+s[j-1]-mn>=lim) L[j]=true;
        if(L[j])  mn=min(mn,s[j]);
    }
    mn=-1e9;
    for(int j=n-1;j;j-=2)
    {
        int fg=0;
        if(tot[0]+s[n]-s[j]>=lim) fg=1;
        if(tot[0]+mn-s[j]>=lim) fg=1;
        if(fg&&L[j]) return true;
        if(fg) mn=max(mn,s[j-1]);
    }
    return false;
}
int main()
{   
    n=read();
    for(int i=1;i<=n;++i) a[i]=read(),tot[i&1]+=a[i];
    if(~n&1) return 0*printf("%d %d\n",max(tot[0],tot[1]),min(tot[1],tot[0]));
    ans=max(tot[0],tot[1]);
    int l=ans+1,r=tot[0]+tot[1],mid;
    for(int i=1;i<=n;++i) s[i]=s[i-1]+((i&1)?1:-1)*a[i];
    while(l<=r)
    {
        mid=l+r>>1;
        if(Solve(mid)) ans=mid,l=mid+1;
        else r=mid-1;
    }
    printf("%d %d\n",ans,tot[0]+tot[1]-ans);
    return 0;
}

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

#define println(msg) cout << msg << endl
#define sort_vec(vec) sort(vec.begin(), vec.end())

int main() {
  // 入力
  int N, L;
  cin >> N >> L;

  vector<string> S(N);
  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  
  // 計算
  sort_vec(S);
  string result = "";
  for (auto s : S) {
    result += s;
  }
  
  // 出力
  println(result);
}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> up(n);
  vector<int> down(n);
  for(int i=0;i<n;i++){
    cin >> up[i];
  }
  int dsum=0;
  for(int i=0;i<n;i++){
    cin >> down[i];
    dsum+=down[i];
  }
  int ans=up[0]+dsum;
  int sum=ans;
  for(int i=1;i<n;i++){
    sum=sum+up[i]-down[i-1];
    if(ans<sum) ans=sum;
  }

  cout << ans << "\n";
  
  return 0;
}


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

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  int x = r * 100 +   g * 10 + b;
  if (x % 4 == 0) {
    cout << "YES";
  } else {
    cout << "NO";
  }
  cout << endl;
}


Measured memory_bytes: 3648
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

string s;

int main()
{
	int i, j, k, l;
	cin>>s;
	cout<<s[0]<<s[1]<<s[2]<<s[3]<<' ';
	for(i=4;i<12;i++) cout<<s[i];
	cout<<endl;
	return 0;
}
//*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)n;i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
int INF = 1e18;

vector<int>g[202];
int flg = 1;
void dfs(int now,int color,vector<int>&col){
	col[now]=color;
	if(color==1)color=0;
	else color=1;
	for(auto e:g[now]){
		if(col[e]!=-1&&col[e]!=color)flg=0;
		if(col[e]!=-1)continue;
		dfs(e,color,col);
	}
}
int d[202][202];
void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

signed main(){
	int N;
	cin>>N;
	string s[N];
	REP(i,N)cin>>s[i];
	REP(i,N)FOR(j,i+1,N){
		if(s[i][j]=='1'){
			g[i].push_back(j);
			g[j].push_back(i);
		}
	}
	vector<int>col(N,-1);
	dfs(0,1,col);
	if(flg==0){
		cout<<-1<<endl;
		return 0;
	}
	REP(i,N)REP(j,N)d[i][j]=INF;
	REP(i,N){
		REP(j,N)if(s[i][j]=='1')d[i][j]=1;
	}
	warshall_floyd(N);
	int ans = 0;
	REP(i,N)FOR(j,i+1,N)CHMAX(ans,d[i][j]);
	cout<<ans+1<<endl;
}

Measured memory_bytes: 896
#include<stdio.h>
int main(void){
int a,b,c,t;
scanf("%d%d%d",&a,&b,&c);
if(b>c){t=b;b=c;c=t;}
if(a>b){t=a;a=b;b=t;}
if(b>c){t=b;b=c;c=t;}
printf("%d %d %d\n",a,b,c);
return 0;}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

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

int showAll(map<string, int> mp) {
  map<string, int>::iterator itr;
  for (itr = mp.begin(); itr != mp.end(); itr++) {
    cout << itr->first << " => " << itr->second << " / ";
  }
  cout << endl;
  return 0;
}

int main() {
  int n;
  cin >> n;
  string s;
  map<string, int> mp;
  map<string, int>::iterator itr;
  int maxIndex = -1;
  int max = 0;
  rep (i, n) {
    cin >> s;
    itr = mp.find(s);
    if (itr != mp.end()) itr->second++;
    else mp[s] = 1;
    if (max < mp[s]) {
      max = mp[s];
    }
  }
  // showAll(mp);
  // cout << max << endl;
  vector<string> v;
  for (itr = mp.begin(); itr != mp.end(); itr++) {
    if (itr->second == max) v.push_back(itr->first);
  }
  sort(v.begin(), v.end()); // 昇順ソート
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 26868
n,x,y = map(int, input().split())
x,y = x-1,y-1
dis = []

for i in range(n):
  for j in range(i+1,n):
    a = abs(j-i)
    xy = abs(i-x) + abs(j-y) + 1
    dis.append(min(a,xy))

ans = [0]*(n-1)
for d in dis:
  ans[d-1] += 1

for a in ans:
  print(a)

Measured memory_bytes: 67348
s = input()
n = len(s)

if s!=s[::-1]:
    print("No")
    exit(0)

s1 = s[:(n-1)//2]
if s1!=s1[::-1]:
    print("No")
    exit(0)

s2 = s[(n+3)//2-1:n]
if s2!=s2[::-1]:
    print("No")
    exit(0)

print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int n,m;
int shukuba[100010];
int dist[100010];

void solve(){
  int pos = 1;
  int x = 0;
  int ans = 0;

  rep(i,m){
    int next = shukuba[pos+dist[i]];
    ans = (ans + abs(next - x)) % 100000;
    x = next;
    pos += dist[i];
  }
  cout<<ans<<endl;
}

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

  shukuba[1] = 0;
  REP(i,2,n+1){
    int x;
    cin>>x;
    shukuba[i] = shukuba[i-1] + x;
  }
  rep(i,m){
    cin>>dist[i];
  }

  solve();
}

Measured memory_bytes: 1620
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
inline int check(int x){
	for(int i=1;i*(i-1)<=x;++i) if(i*(i-1)==x) return i;
	return 0;
}
const int maxn=1e3+10;
vector<int> ve[maxn];
int main(){
	int n=read();
	int m=check(2*n);
	if(!m) return printf("No\n"),0;
	printf("Yes\n%d\n",m);
	int Nw=1;
	REP(i,1,m)
		REP(j,i+1,m){
			ve[i].push_back(Nw);
			ve[j].push_back(Nw);
			++Nw;
		}
	REP(i,1,m){
		printf("%d ",ve[i].size());
		for(auto v:ve[i]) printf("%d ",v);
		putchar('\n');
	}
	return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long int
#define pb push_back
#define all(a) a.begin(),a.end()

int gcd(int m,int n){
	if(m%n==0) return n;
	return gcd(n,m%n);
}

signed main(){
	IOS;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int x1=a/c, y1=b/c;
	int x2=a/d, y2=b/d;
	int e=c*d/gcd(c,d);
	int x=a/e, y=b/e;
	int ans=0;
	ans+=(y1-x1)+(y2-x2);
	if(a%c==0) ans++;
	if(a%d==0) ans++;
	ans-=(y-x);
	if(a%e==0) ans--;
	cout<<(b-a+1-ans);
	// int x1=a+(c-a%c),x2=a+(d-a%d);
	// int y1=b-(b%c),y2=b-(b%d);
	// if(a%c==0){
	// 	x1-=c;
	// }
	// if(b%c==0){
	// 	x2-=c;
	// }
	// int e=(c*d/gcd(c,d));
	// // cout<<e<<endl;
	// int x=a+(e-a%e),y=b-(b%e);
	// if(a%e==0){
	// 	x-=e;
	// }
	// int ans=0;
	// if(y1>=x1){
	// 	ans += ((y1-x1)/c+1);
	// }
	// if(y2>=x2){
	// 	ans += ((y2-x2)/d+1);
	// }
	// if(y>=x){
	// 	ans -= ((y-x)/e+1);
	// }
	// // cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<" "<<x<<" "<<y<<endl;
	// cout<<(b-a+1)-ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll     long long int
#define ull   unsigned long long int
#define mod 1000000007
using namespace std;
 
 ll btod(string v){
     ll sum=0;
     for(int i=0;i<v.size();i++){
         sum+=pow(2,i)*v[i];
     }
     return sum;
 }
  string dtob(ll a){
     string v;
     while(a){
         v.push_back(a%2+'0');
         a/=2;
     }
     return v;
 }
 
 ll find(ll a,vector<ll> &parent){
 //    cout<<parent[a];
 vector<ll> parenti = parent;
     while(parenti[a]!=a){
         parenti[a]=parenti[parenti[a]];
         a=parenti[a];
     }
     return a;
 }
 
void unioni(ll x,ll y,vector<ll>&parent){
    ll x1=find(x,parent);
    ll y1=find(y,parent);
  // cout<<x<<" "<<y<<" "<<x1<<" "<<y<<endl;  
 
    
    if(x1<y1){
        parent[y1]=x1;
    }
    else{
        parent[x1]=y1;
    }
    
    
    
}
 
 
 
long long int power(long long int x,   long long int y,   long long int m)
{
    if (y == 0)
        return 1;
    long long int p = power(x, y/2, m) % m;
    p = (p * p) % m;
 
    return (y%2 == 0)? p : (x * p) % m;
}
 
 
long long int gcd(long long int a, long long int b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
ll modInverse(long long int a, long long int m)
{
     
         
             long long int t =  (power(a, m-2, m))%1000000009;
           
            return t;
    
}
 
  int recur(int n ,int a,int b,int c){
      if(n==0)return 0;
      if(n<0)return INT_MIN;
        return 1+max(recur(n-a,a,b,c),max(recur(n-b,a,b,c),recur(n-c,a,b,c))); 
  }
 
int main(){
 
 string s;cin>>s;
 string ans;
 for(int i=0;i<s.size();i++){
     if(s[i]-48==9)ans.push_back('1');
     if(s[i]=='1')ans.push_back('9');
 }
  cout<<ans;
      
      
      
}

Measured memory_bytes: 256
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from functools import *
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def Golf():
    *a,=map(int,open(0))
def S_():
    return input()
def IS():
    return input().split()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0}):
#h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0}) # sample usage
    mp=[1]*(w+2)
    found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[1]+[mp_def[j] for j in s]+[1]
    mp+=[1]*(w+2)
    return h+2,w+2,mp,found
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['YES','NO']
Yn=['Yes','No']
 
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
#ts=time.time()
#sys.setrecursionlimit(10**7)
input=lambda: sys.stdin.readline().rstrip()
 
def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n,a,b=LI()
ans+=n//(a+b)*a
ans+=min(n%(a+b),a)
print(ans)


Measured memory_bytes: 39532