akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N=nextInt();
		int D=nextInt();
		long[][] x=new long[N][];
		for(int i=0;i<N;i++){
			x[i]=nextLongs();
		}

		long ans =0;
		for(int i=0;i<N;i++){
			for(int k=i+1;k<N;k++){
				long d = 0;
				for(int z=0;z<D;z++){
					d+=Math.pow(x[i][z]-x[k][z],2);
				}
				if(Math.sqrt(d)-(long)Math.sqrt(d)==0){
					ans++;
				}
			}
		}
System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 23124
//O(ElogV)
#define LOCAL0
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
#define INF 0x3f3f3f3f
typedef long long ll;
using namespace std;
inline void read(int &p)
{
    p=0;int flag=1;char c=getchar();
    while(!isdigit(c)) {if(c=='-') flag=-1;c=getchar();}
    while(isdigit(c)) {p=p*10+c-'0';c=getchar();}p*=flag;
}
inline void write(int x)
{
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}

const int MAX_E=200005,MAX_V=100005;
int V,E,s=1,ans;
struct edage
{
    int to;
    int len;
    int w;
};
vector<edage> e[MAX_E];
struct node
{
    int num;
    int dis;
    bool operator < (const node& x) const
    {
        return dis>x.dis;
    }
};

int d[MAX_V];
bool vis[MAX_V];
int value[MAX_V];

void dij()
{
    priority_queue<node> pq;
    for(int i=1;i<=V;i++) {d[i]=INF;value[i]=0;vis[i]=0;}
    d[s]=0;
    pq.push((node){s,0});
    while(!pq.empty())
    {
        int u=pq.top().num;
        pq.pop();
        if(vis[u]) continue;
        vis[u]=1;
        for(int i=0;i<e[u].size();i++)
        {
            edage es=e[u][i];
            if(d[es.to]>d[u]+es.len)
            {
                value[es.to]=es.w;
                d[es.to]=d[u]+es.len;
                pq.push((node){es.to,d[es.to]});
            }
            else if(d[es.to]==d[u]+es.len){
                value[es.to]=min(value[es.to],es.w);
            }
        }
    }
}
int main()
{
    #ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    while(cin>>V>>E){
    if(!V) break;
    ans=0;
    for(int i=1;i<=V;i++) e[i].clear();
    int x,y,z,w;
    for(int i=1;i<=E;i++)
    {
        read(x),read(y),read(z),read(w);
        e[x].push_back((edage){y,z,w});
        e[y].push_back((edage){x,z,w});
    }
    dij();
    for(int i=1;i<=V;i++){
        ans+=value[i];
    } 
    cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 9648
using System;

namespace debug
{
    class Program
    {
        static void Main(string[] args)
        {
            ProgramC a = new ProgramC();
            a.main();

        }
    }

    //ABC115
    class ProgramA
    {
        public void main()
        {
            int D = int.Parse(Console.ReadLine());

            if (D == 25)
                Console.WriteLine("Christmas");
            else if (D == 24)
                Console.WriteLine("Christmas Eve");
            else if (D == 23)
                Console.WriteLine("Christmas Eve Eve");
            else
                Console.WriteLine("Christmas Eve Eve Eve");
        }
    }

    //ABC162
    class ProgramB
    {
        public void main()
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = int.Parse(Console.ReadLine());

            Array.Sort(a);
            int ans = 0;
            
            for (int i = 0; i < n; i++)
            {
                //偶数の時
                if (i == n - 1)
                {
                    ans += a[i] / 2;
                }
                else
                    ans += a[i];

            }

            Console.WriteLine(ans);
        }
    }

    //ABC161_F問題
    
    class ProgramC
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            long[] a = new long[n];

            for (int i = 0; i < n; i++)
                a[i] = long.Parse(Console.ReadLine());

            Array.Sort(a);

            long ans = 1000000000000;

            for (int i = k - 1; i < n; i++)
            {
                ans = Math.Min(ans, a[i] - a[i - k + 1]);
            }

            Console.WriteLine(ans);
        }
    }

    class ProgramD
    {
        public void main()
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int k = int.Parse(s[1]);
            int[] a = new int[n];

            for (int i = 0; i < n; i++)
                a[i] = int.Parse(Console.ReadLine());

            Array.Sort(a);

            long ans = 100000000;

            for (int i = k - 1; i < n; i++)
            {
                ans = Math.Min(ans, a[i] - a[i - k + 1]);
            }

            Console.WriteLine(ans);
        }
    }


}


Measured memory_bytes: 15964
#include <bits/stdc++.h>
#define fr(a) freopen(a,"r",stdin)
#define fw(a) freopen(a,"w",stdout)
#define reset(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
#define pb push_back
#define ins insert
#define mp make_pair
#define fi first
#define se second
#define bug(x) cout << #x << " = " << x << endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int llu;
typedef long double lf;
typedef pair<int,int>pii;
typedef pair<ll,ll>pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int main(){
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<"Draw";
    }
    else if(a>b&&b!=1||a==1) cout<<"Alice";
    else cout<<"Bob";
    return 0;
}





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

using namespace std;


int main (void) 
{

  int N; // 操作A,Bの合計
  int K; // 操作Bで加算する値

  int i;
  int data; // output

  cin >> N;
  cin >> K;
  data = 1;

  for(i=0; i<N; i++)
  {
    // 操作A
    if(data <= K)
    {    
      data *= 2;
    }
    // 操作B
    else
    {
      data += K;
    }
  }

  cout << data << endl;
  

  return 0;

}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int main() {
	int n;
	cin>>n;
	vector<double> p (n);
	for(int i=0;i<n;i++) {
		cin>>p[i];
	}
	// p ( H > T)
	// dp[i][j] = probability(i Heads and j Tails)
	// dp[i][j] = dp[i-1][j] i -> HEADS
	// dp[i][j] = dp[i][j-1] i -> TAIL
	// reverse iterative process
	// dp[i] Heads = dp[i] * (1 - p[i]) + dp[i-1] * p[i];
	// dp[0] = 1
	vector<double> dp (n+1);
	dp[0] = 1.0;
	for (int i = 0; i < n; ++i) {
		for(int j = i+1; j>=0; j--) {
			dp[j] = dp[j] * (1.0 - p[i]) + dp[j-1] * p[i];
		}
	}
	// 4/2 + 1
	// 3/2 
	double ans = 0.0;
	for(int i = n/2 + 1; i<=n;i++) {
		ans += dp[i];
	}
	cout<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
// failed to generate code

#include <algorithm>
#include <bitset>
#include <cassert>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define POW(n) ((n) * (n))
#define ALL(a) (a).begin(), (a).end()

using namespace std;

namespace Dump {
#define dump(...) Dump::print(#__VA_ARGS__, __VA_ARGS__)
static std::vector<string> dumpKey;
static string dumpKeyBuf;

void print() { cerr << endl; }
template <class Head, class... Tail> void print(Head &&head, Tail &&... tail) {
  if (dumpKey.empty()) {
    dumpKeyBuf = head;
    dumpKeyBuf.erase(std::remove_if(dumpKeyBuf.begin(), dumpKeyBuf.end(),
                                    [](char c) { return c == ' '; }),
                     dumpKeyBuf.end());

    std::istringstream stream(dumpKeyBuf);
    string field;
    while (std::getline(stream, field, ','))
      dumpKey.push_back(field);

    reverse(dumpKey.begin(), dumpKey.end());
  } else {
    cerr << dumpKey.back() << ":" << head << "  ";
    dumpKey.pop_back();
  }
  Dump::print(std::move(tail)...);
}
}

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<unsigned long long> vull;
typedef pair<int, int> pii; // p.first p.second

// ll n = to_T<ll>("114514")
template <class T> T to_T(const string &s) {
  istringstream is(s);
  T res;
  is >> res;
  return res;
}
template <class T> string to_s(const T &a) {
  ostringstream os;
  os << a;
  return os.str();
}

int binarySearch(long double key) {
  if (key == 0)
    return -1;
  int left = 0;
  int right = 3501;

  //残り10以下になるまで探索
  while (right - left > 10) {
    int mid = (left + right) / 2;
    long double buf = 1.d / mid;

    if (buf == key)
      return mid;

    if (buf > key) {
      left = mid;
    } else {
      right = mid;
    }

    // cerr << left << " " << right << endl;
  }

  //あとは愚直に
  for (int i = left; i <= right; ++i) {
    long double buf = 1.d / i;

    if (buf == key) {
      return i;
    }
  }

  return -1;
}

ll N;

void think() {
  cin >> N;

  long double ans = 4.d / N;

  // if (false) {
  for (ll h = 1; h < 3501; ++h) {
    for (ll n = 1; n < 3501; ++n) {
      // long double buf = ans - 1.d / h - 1.d / n;
      // if (buf <= 0)
      // continue;

      ll w = h * n * N / (long double)(4 * h * n - h * N - n * N);

      // dump(binarySearch(buf));
      // dump(ans, buf);
      // int w = binarySearch(buf);
      if (w <= 0)
        continue;

      // if (ans !=
      // (1 / (long double)h + 1.d / (long double)n + 1.d / (long double)w))
      // continue;

      if (N * (h * (n + (ll)w) + n * w) != 4 * h * n * (ll)w)
        continue;

      dump(ans, (1.d / h + 1.d / n + 1.d / w));
      cout << h << " " << n << " " << w << endl;
      return;
    }
  }
  // }
}

int main() {
  ios::sync_with_stdio(false);
  think();
}


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

using namespace std;

int ans = 0;
bool dfs(vector< vector<int> > &island,int x,int y){
	int dx[8] = {-1,-1,-1, 0, 0, 1, 1, 1};
	int dy[8] = {-1, 0, 1,-1, 1,-1, 0, 1};
	if (island[x][y] == 0) return false;
	island[x][y] = 0;
	for (int i = 0; i< 8; i++){
		if(0 <= x + dx[i] and x + dx[i] < island.size() and 0 <= y + dy[i] and y + dy[i] < island[0].size()){
			dfs(island,x + dx[i],y + dy[i]);
		}
	}
	return true;
}

int main(){
	while(1){
		int w,h; cin >> w >> h;
		int ans = 0;
		if (w + h == 0) break;
		vector< vector<int> > island(h, vector<int>(w,0));
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				cin >> island[i][j];
			}
		}

		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if (dfs(island,i,j)){
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
return 0;
}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
#define MAX 5000
#define INF 998244353
using namespace std;

int dp[MAX][MAX];
int arr[MAX];
int canOpen[MAX];

int main(void)
{
	int N, M;
	cin >> N >> M;
	for (int i = 1; i < (1 << N); i++) dp[0][i] = INF;
	for (int i = 0; i < M; i++)
	{
		int t;
		cin >> arr[i];
		cin >> t;
		for (int j = 0; j < t; j++)
		{
			int x;
			cin >> x;
			x--;
			canOpen[i] |= (1 << x);
		}
		for (int j = 0; j < (1 << N); j++) dp[i + 1][j] = dp[i][j];
		for (int j = 0; j < (1 << N); j++) dp[i + 1][j | canOpen[i]] = min(dp[i + 1][j | canOpen[i]], dp[i][j] + arr[i]);
	}
	if (dp[M][(1 << N) - 1] == INF) cout << -1 << endl;
	else cout << dp[M][(1 << N) - 1] << endl;
	return 0;
}


Measured memory_bytes: 20736
#!/usr/bin/env python3
from itertools import product
import sys

try:
    from typing import List, Tuple
except ImportError:
    pass


MOD = 1000000007  # type: int


def isvalid(ptn: "Tuple[bool]"):
    return not any(h1 and h2 for h1, h2 in zip(ptn, ptn[1:]))


def solve(H: int, W: int, K: int):
    validptns = [
        ptn
        for ptn in product((False, True), repeat=W - 1)
        if isvalid(ptn)
    ]  # type: List[Tuple[bool]]
    dp = [1 if i == K - 1 else 0 for i in range(W)]  # type: List[int]
    for _ in range(H):
        newdp = [0] * W  # type: List[int]
        for ptn in validptns:
            for s in range(W):
                t = s
                if s < W - 1 and ptn[s]:
                    t = s + 1
                elif s > 0 and ptn[s - 1]:
                    t = s - 1
                newdp[t] += dp[s]
                newdp[t] %= MOD
        dp = newdp

    print(dp[0])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(H, W, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
int main(){
int a;
cin >> a;
vector<int> list(a);
for(int i = 0; i < a; i++){
    cin >> list.at(i);
}
for(int i = 0; i < a; i++){
    cout << list[i];
    if(i != a - 1)
    cout << " ";
    if(i == a - 1)
    cout << endl;
}
for(int i = 1; i < a; i++){
    int v = list[i];
    int j = i - 1;
    while(j >= 0 && list[j] > v){
        list[j + 1] = list[j];
        j--;
        list[j + 1] = v;
    }
for(int k = 0; k < a; k++){
if(k <= a - 2)
cout << list[k] << " ";
else
{
    cout << list[k] << endl; 
}

}
}
}


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

int main()
{
  LL n,D;
  LL sum=0;
  cin >> D >> n;

  for(LL i=0,d=0;d <= n;i+=pow(100,D),d++){
    sum = i;
  }
  if( (D == 0 || D == 1 || D == 2) && n == 100){
    cout << (LL)(pow(100,D+1)+pow(100,D)) << endl;
  }
  else cout << sum << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

int main(){
    int n,k,y;
    double p=0.0,x;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++){
        x=log2f(k)-log2f(i);
        y=x;
        if(y!=x){
            y+=1;
        }
        if(i<k){
            p+=1.0/(n*powl(2.0,y));
        }
        else{
            p+=((double)n-(double)k+1.0)/(double)n;
            break;
        }
    }
    printf("%.10lf\n",p);
}


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

using namespace std;

#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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

string lefth="yuiophjklnm";


int main(){
 
    while(true) {
        string s;
        cin>>s;
        if(s=="#")break;
        
        string hand;
        REP(i,s.size()){
            REP(j,lefth.size()){
                if(s[i]==lefth[j]){
                    hand=hand+'1';
                    goto nextf;
                }
            }
            hand=hand+'0';
        nextf:;
        }
        
        char c=hand[0];
        int ans=0;
        REP(i,hand.size()){
            if(c!=hand[i]){
                ans++;
                c=hand[i];
            }
        }
        
        cout<<ans<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3192
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int c, m, a, n;
	state(int c, int m, int a, int n) : c(c), m(m), a(a), n(n) {};
};

int main() {
	int p, q, a, n;
	while(cin >> p >> q >> a >> n, p) {
		stack<state> S;
		FOR(i, 1, a) {
			S.push(state(1, i, i, 1));
		}

		int ans = 0;
		while(!S.empty()) {
			state st = S.top();
			S.pop();

			if(p*st.m == q*st.c) {
				ans++;
				continue;
			}

			if(st.n == n) {
				continue;
			}

			FOR(i, st.a, a) {
				int nm = st.m*i;
				if(a < nm) {
					break;
				} else {
					int nc = i*st.c+st.m;
					S.push(state(nc, nm, i, st.n+1));
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

long long x, y, d; // ax + by = d
void extendedEuclidean(long long a, long long b) {
  if(b == 0) { x = 1; y = 0; d = a; return; } 
  extendedEuclidean(b, a % b); 
  long long xx, yy;
  xx = y;
  yy = x - (a/b)*y;
  x = xx; y = yy;
}

int main() {
  long long n;
  scanf("%lld", &n);
  if (n == 1) {
    puts("1");
    return 0;
  }
  long long ans = 2 * n - 1;
  for (long long a = 1; a * a <= n; ++a) {
    if (n % a) continue;
    long long b = n / a;
    long long u = a, v = b;
    if (a & 1) {
      u = a, v = b * 2;
      extendedEuclidean(u, v);
      if (d == 1 && x && y) {
        ans = min(ans, min(abs(u * x), abs(v * y)));
      }
    }
    if (b & 1) {
      u = a * 2, v = b;
      extendedEuclidean(u, v);
      if (d == 1 && x && y) {
        ans = min(ans, min(abs(u * x), abs(v * y)));
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3824
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class CXYZTriplets {
public:
    int eval(int a, int b,int c){
        return a*a+b*b+c*c+a*b+b*c+c*a;
    }
    bool bin(int i, int j, int n){
        int lo=1,hi=1000,mid;
        while (hi>=lo){
            mid=(hi+lo)/2;
            int val=eval(i,j,mid);
            if (val>n)
                hi=mid-1;
            else if (val<n)
                lo=mid+1;
            else return true;
        }
        return false;
    }
	void solve(std::istream& cin, std::ostream& cout) {
        int n;
        cin>>n;
        for (int k=1;k<=n;k++){
            int count=0;
            for (int i=1;i<=(int)(sqrt(n)+1);i++){
                for (int j=1;j<=(int)(sqrt(n)+1);j++){
                    if (bin(i,j,k))
                        count++;
                }
            }
            cout<<count<<endl;
        }
	}
};


int main() {
	CXYZTriplets solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define rev(a) (a).rbegin(),(a).rend()
#define pll pair<ll,ll>
#define rep(i,a,b) for(long long i = (a); i <= (b); i++)

const int mod = 1e9+7;
const int N = 1e5+5; 

int main(){
	fast;
	ll t = 1; 
	//cin >> t;
	while(t--){
	    ll n,a,b; cin >> n >> a >> b;
	    ll ans = 0;
	    ll s = a + b;
	    ans = (n / s) * (a);
	    ans += min(n % s,a);
	    cout << ans << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A > B) {
			System.out.println(0);
			return;
		}
		if (N == 1) {
			System.out.println(A == B ? 1 : 0);
			return;
		}
		long min = Math.addExact(Math.multiplyExact(A, N - 1L), B);
		long max = Math.addExact(Math.multiplyExact(B, N - 1L), A);
		System.out.println(max - min + 1);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 21972
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

template <typename T>
using vec = vector<T>;

template <typename T>
using vec2 = vector<vector<T>>;

template <typename T>
using vec3 = vector<vector<vector<T>>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

template <typename T>
T Lcm(T a, T b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

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

    Int n, m;
    cin >> n >> m;
    vec<Int> a(n), b(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i] / 2;
    }

    bool isok = true;
    Int div2 = 0;
    for (Int i = a.front(); !(i & 1);) {
        div2++;
        i /= 2;
    }

    for (Int i = 1; i < n; i++) {
        Int tem = 0;
        for (Int j = a[i]; !(j & 1);) {
            tem++;
            j /= 2;
        }

        if (div2 != tem) {
            isok = false;
            break;
        }
    }

    if (isok) {
        Int lcm_b = 1;
        for (Int i = 0; i < n; i++) {
            lcm_b = Lcm(lcm_b, b[i]);
        }

        cout << (m / lcm_b + 1) / 2 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 4704
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

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

const int L=200000+1;
vector<int> ps[L];
int main() {
	int N;
	cin >> N;
	for(int i=1;i<=N;i++){
		int a;
		cin >> a;
		ps[a].push_back(i);
	}
	int p=0;
	for(int i=1;i<=N;i++){
		auto it=lower_bound(ps[i].begin(),ps[i].end(),p);
		if(it==ps[i].end()){
			if(i==1){
				cout << -1 << endl;
			}
			else{
				cout << N-i+1 << endl;
			}
			return 0;
		}
		p=*it;
	}
	cout << 0 << endl;

	return 0;
}



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

const int INF = 1e9;

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

  pair<int, int> cb[m];
  for (int i=0; i<m; i++) {
    int bi, ci;
    cin>>bi>>ci;
    cb[i] = make_pair(ci, bi);
  }

  sort(a, a+n);
  sort(cb, cb+m);
  reverse(cb, cb+m);

  int x[n];
  int idx = 0;
  for (int i=0; i<m; i++) {
    for (int j=0; j<cb[i].second; j++) {
      x[idx] = cb[i].first;
      ++idx;
      if (idx >= n) {
        break;
      }
    }
    if (idx >= n) {
      break;
    }
  }
  for (int i=idx; i<n; i++) {
    x[i] = 0;
  }
  long long acc_a[n+1];
  acc_a[0] = 0;
  for (int i=1; i<=n; i++) {
    acc_a[i] = acc_a[i-1] + a[i-1];
  }
  long long  acc_x[n+1];
  acc_x[0] = 0;
  for (int i=1; i<=n; i++) {
    acc_x[i] = acc_x[i-1] + x[i-1];
  }

  long long ans = 0;
  for (int i=0; i<=n; i++) {
    ans = max(ans, acc_x[i] + acc_a[n] - acc_a[i]);
  }
  cout<<ans<<endl;
}

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

int main(){
	int N, M;
	cin >> N >> M;
	int i, j, a[M], b[M];
	for(i=1; i<=M; i++){
		cin >> a[i] >> b[i];
	}
	
	int count[N];
	for(i=1; i<=N; i++){
		count[i]=0;
	}
	for(i=1; i<=N; i++){
		for(j=1; j<=M; j++){
			if(i==a[j] || i==b[j])	count[i]++;
		}
	}
	for(i=1; i<=N; i++){
		cout << count[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int h,w;
	cin >> h >> w;
	vector<char> c(w);
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> c.at(j);
		}
		for(int j=0; j<w; j++){
			cout << c.at(j);
		}
		cout << endl;
		for(int j=0; j<w; j++){
			cout << c.at(j);
		}
		cout << endl;
	}
	return 0;
}

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

int main()

{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if(a>b)
        a=b;
    if(c>d)
        c=d;
    printf("%d\n",a+c);
    return 0;
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		Map<String, Integer> smap = new HashMap<>();
		Map<String, Integer> tmap = new HashMap<>();

		for (int i = 0; i < s.length(); i++) {
			if (smap.containsKey(String.valueOf(s.charAt(i)))) {
				smap.put(String.valueOf(s.charAt(i)), (smap.get(String.valueOf(s.charAt(i)))+1));
			} else {
				smap.put(String.valueOf(s.charAt(i)), 1);
			}
		}
		for (int i = 0; i < t.length(); i++) {
			if (tmap.containsKey(String.valueOf(t.charAt(i)))) {
				tmap.put(String.valueOf(t.charAt(i)), (tmap.get(String.valueOf(t.charAt(i)))+1));
			} else {
				tmap.put(String.valueOf(t.charAt(i)), 1);
			}
		}
		if (smap.size() != tmap.size()) {
			System.out.println("No");
			return;
		}
		List<String> slist = new ArrayList<>(smap.keySet());
		List<String> tlist = new ArrayList<>(tmap.keySet());
		List<Integer> stemp = new ArrayList<>();
		List<Integer> ttemp = new ArrayList<>();
		for (int i = 0; i < slist.size(); i++) {
			stemp.add(smap.get(slist.get(i)));
			ttemp.add(tmap.get(tlist.get(i)));
		}
		Collections.sort(stemp);
		Collections.sort(ttemp);
		if (!stemp.equals(ttemp)) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 50232
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const int mod=1e9+7;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
VI a;
int main(){
//    freopen("B-small-attempt1.in","r",stdin);
//    freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    int mx=SZ(s);
    for(int i=0;i<26;i++){
        int cnt=0;
        a.clear();
        for(auto j:s){
            if(j-'a'==i){
                a.pb(cnt);
                cnt=0;
            }
            else {
                cnt++;
            }
        }
        a.pb(cnt);
        int l=SZ(a);
        if(!l) continue;
        int ans=0;
        for(int j=0;j<l;j++){
            ans=max(ans,a[j]);
        }
        mx=min(mx,ans);
    }
    cout<<mx<<endl;
	return 0;
}
/*
*/


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.mutable.ArrayBuffer


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = for (_ <- 0 until n) yield sc.nextLong()
    (n, a)
  }

  def divisor(n: Long): IndexedSeq[Long] = {
    val buf = ArrayBuffer.empty[Long]
    for (i <- 1 to Math.sqrt(n).toInt) {
      if (n % i == 0) {
        buf.append(i)
        if (i * i != n) {
          buf.append(n / i)
        }
      }
    }
    buf.toIndexedSeq
  }

  def solve(n: Int, a: IndexedSeq[Long]): Long = {
    val cand = IndexedSeq.concat(divisor(a(0)), divisor(a(1))).distinct.sorted

    def satysfies(x: Long): Boolean = {
      a.count(ae => ae % x == 0) >= a.length - 1
    }
    cand.filter(satysfies).max
  }

  def main(args: Array[String]): Unit = {
    val (n, a) = read()
    println(solve(n, a))
  }
}

Measured memory_bytes: 52680
MOD = 1000000007

def conv(a,b)
  if b > a/2
    b = a - b
  end
  ans = 1
  div = 1
  b.times do |i|
    ans *= a - i
    ans %= MOD
    div *= (i+1)
    div %= MOD
  end
  ans = ans * pow(div, MOD-2)
  ans % MOD
end

def pow(x,n)
  if n == 0
    1
  elsif n % 2 == 0
    pow(x*x%MOD, n/2) % MOD
  else
    x * pow(x, n-1) % MOD
  end
end

n,a,b=gets.chomp.split(" ").map(&:to_i)

all = (pow(2,n) - 1) % MOD
if a > n/2
  a = n - a
end
if b > n/2
  b = n - b
end

all = all - conv(n,a) - conv(n,b)
all %= MOD

puts all

Measured memory_bytes: 1788
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem0232 : Life Game **/
int X, Y;
int getm[110], prog[110];
vector<int> rou;

//dp[i][j] := j円持ってiマス目に止まる確率
double dp[101][5001];

int main()
{
	int Z;
	while (cin>>X>>Y>>Z, X) {
		memset(getm, 0, sizeof(getm));
		memset(prog, 0, sizeof(prog));
		
		rou.resize(X);
		rep(i, X) cin>>rou[i];
		
		rep(i, Z) {
			int a, b, c; cin>>a>>b>>c;
			if (b == 1) {
				prog[a] = c;
			} else {
				getm[a] = c * (b==2?1:-1);
			}
		}
		
		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1.0;
		for (int i=0; i<Y; i++) {
			for (int j=0; j<=5000; j++) {
				for (int k=0; k<X; k++) {
					int nc = i+rou[k];
					dp[min(Y, nc+prog[nc])][max(0, j+getm[nc])] += dp[i][j]/X;
				}
			}
		}
		
		double ans=0;
		for (int j=0; j<=5000; j++) {
			ans += dp[Y][j]*j;
		}
		
		cout << (int)ans << endl;
	}
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << #x << " = " << x << endl;
typedef long long ll;


const int MAXN = 100005;
const int MAXP = 10000;


map<ll, ll> m;
map<ll, ll> inv;

vector <ll> p;
bool sieve[MAXP];

ll rooot(ll x)
{
    ll h = (ll)sqrt(x);
    if (h*h == x) return h;
    return 0;
}


int main()
{
    //freopen("input.txt", "r", stdin);

    for (ll i = 2; i < MAXP; i++)
    {
        if (sieve[i]) continue;
        p.push_back(i);
        for (ll j = i; j < MAXP; j+=i)
        {
            sieve[j] = true;
        }
    }

    int n;
    cin >> n;

    ll ans = 0;
    for (int j = 0; j < n; j++)
    {
        ll a;
        cin >> a;

        ll huj = 1;
        ll pzd = 1;
        for (ll i = 0; a > 1 && p[i] * p[i] <= a && i < p.size(); i++)
        {
            ll pwd = 0;

            while(a % p[i] == 0)
            {
                pwd++;
                a/=p[i];
            }
            pwd %= 3;

          //  cout << p[i] << " " << pwd << endl;

            for (int j = 0; j < pwd; j++) huj*=p[i];
            for (int j = 0; j < (3-pwd)%3; j++) pzd*=p[i];
        }

        if (a >= MAXP)
        {
            ll sq = rooot(a);
            if (sq)
            {
                huj *= a;
                pzd *= sq;
            }
            else
            {
                if (a <= 100005)
                {
                    huj *= a;
                    pzd *= a*a;
                }
                else
                {
                    ans++;
                    continue;
                }
            }
        }
        else
        {
            huj *= a;
            pzd *= a*a;
        }
        m[huj]++;
        inv[huj] = pzd;

       // cout << huj << " " << pzd << endl;
    }

//    cout << endl;
    for (auto it = m.begin(); it != m.end(); it++)
    {
  //      cout << it-> first << " " << it-> second << endl;
        ll key1 = it->first;
        ll val1 = it->second;
        ll key2 = inv[key1];
        ll val2 = m[key2];

        if (key1 == key2) ans += min(1LL, val1);
        else if (val1 > val2 || (val1 == val2 && key1 < key2)) ans += val1;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 20864
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=1e5+10;
int n;
string s;
int nr,ng,nb;
ll r1,g1,b1,r2,g2,b2,n3;
vector<int> pr,pg,pb;
int main()
{
	cin>>n;
	cin>>s;
/*	for(int i=0;i<n*3;i++)
	{
		if(s[i]=='R')pr.push_back(i);
		else if(s[i]=='G')pg.push_back(i);
		else pb.push_back(i);
	}*/
//	pr.push_back(inf);
//	pg.push_back(inf);
//	pb.push_back(inf);
	r1=g1=b1=r2=g2=b2=0;
	n3=n;
	ll ans=1ll;
	for(int i=0;i<n*3;i++)
	{
	//	cout<<ans<<" "<<r1<<" "<<g1<<" "<<b1<<" "<<r2<<" "<<g2<<" "<<b2<<endl;
		if(s[i]=='R')
		{
//			nr++;
			if(r2!=0)
			{
				ans*=r2;
				ans%=mod;
				r2--;
			}
			else if(g1!=0||b1!=0)
			{
			    ans*=(g1+b1);
			    ans%=mod;
				if(g1==0)
				{
				//	ans*=1ll*b1;
				//	ans%=mod;
					b1--;
					g2++;
				}
				else
				{
				//	ans*=1ll*g1;
				//	ans%=mod;
					g1--;
					b2++;
				}
			}
			else
			{
			//	assert(n3!=0);
				ans*=n3;
				ans%=mod;
				n3--;
				r1++;
			}
		}
		else if(s[i]=='G')
		{
		//	ng++;
			if(g2!=0)
			{
				ans*=g2;
				ans%=mod;
				g2--;
			}
			else if(r1!=0||b1!=0)
			{
			    ans*=(r1+b1);
				ans%=mod;
				if(r1==0)//||b1!=0&&pr[nr+r2]<pb[nb+b2])
				{
				//	ans*=1ll*b1;
				//	ans%=mod;
					b1--;
					r2++;
				}
				else
				{
				//	ans*=1ll*r1;
				//	ans%=mod;
					r1--;
					b2++;
				}
			//	cout<<ans<<endl;
			}
			else
			{
			//	assert(n3!=0);
				ans*=n3;
				ans%=mod;
				n3--;
				g1++;
			}
		}
		else
		{
		//	nb++;
			if(b2!=0)
			{
				ans*=1ll*b2;
				ans%=mod;
				b2--;
			}
			else if(g1!=0||r1!=0)
			{
			    ans*=(g1+r1);
			    ans%=mod;
			//    cout<<ans<<endl;
				if(g1==0)///||g1!=0&&pg[ng+g2]<pr[nr+r2])
				{
				//	ans*=1ll*r1;
				//	ans%=mod;
					r1--;
					g2++;
				}
				else
				{
				//	ans*=1ll*g1;
				//	ans%=mod;
					g1--;
					r2++;
				}
			}
			else
			{
			//	assert(n3!=0);
				ans*=n3;
				ans%=mod;
				n3--;
				b1++;
			}
		}
	}
	cout<<ans;
	return 0;
}

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

int dist(int a, int b){
    return max(a-b, b-a); }

int dist(pair<int, int> a, pair<int, int> b){
    return min(
        dist(a.first, b.first),
        dist(a.second, b.second)); }

pair<int, int> rev(pair<int, int> a){
    return make_pair(a.second, a.first); }

class merge_find{
    vector<int> tata, rk;
public:
    merge_find(const int n): tata(n), rk(n, 0){
        iota(begin(tata), end(tata), 0); }
    int find(int x){
        return x == tata[x] ? x : tata[x] = find(tata[x]); }
    bool merge(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return false;
        if(rk[x] < rk[y]) swap(x, y);
        if(rk[x] == rk[y]) ++rk[y];
        tata[y] = x;
        return true; } };

int spanning_tree(int n, vector<tuple<int, int, int>> edges){
    merge_find mf(n);
    int rez = 0;
    sort(begin(edges), end(edges));
    for(auto e : edges)
        if(mf.merge(get<1>(e), get<2>(e)))
            rez += get<0>(e);
    return rez; }

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> v_(n);
    
    for(auto& x : v) cin >> x.first >> x.second;

    iota(begin(v_), end(v_), 0);

    sort(begin(v_), end(v_), [&v](const int x, const int y){
        return v[x] < v[y]; });

    vector<tuple<int, int, int>> edges;

    for(int i = 0, j = 1; j < n; ++i, ++j)
        edges.emplace_back(
            dist(v[v_[i]], v[v_[j]]),
            v_[i],
            v_[j]);

    sort(begin(v_), end(v_), [&v](const int x, const int y){
        return rev(v[x]) < rev(v[y]); });

    for(int i = 0, j = 1; j < n; ++i, ++j)
        edges.emplace_back(
            dist(v[v_[i]], v[v_[j]]),
            v_[i],
            v_[j]);

    cout << spanning_tree(n, edges) << endl;
    return 0; }


Measured memory_bytes: 7536
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0630?year=2017

#include <bits/stdc++.h>

using namespace std;

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    if (a > 0) {
        cout << (b - a) * e << endl;
    } else {
        cout << (-a) * c + d + b * e << endl;
    }
    return 0;
}

/*
 *
 */


Measured memory_bytes: 3088
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def init(bit, values):
    for i,v in enumerate(values):
        add(bit,i+1,v)
#a1 ~ aiまでの和 O(logn)
def query(bit,i):
    res = 0
    while i > 0:
        res += bit[i]
        i -= i&(-i)
    return res

#ai += x(logN)
def add(bit,i,x):
    if i==0:
        raise RuntimeError
    while i <= len(bit)-1:
        bit[i] += x
        i += i&(-i)
    return


t = int(input())
ANS = [None]*t
from collections import defaultdict
from heapq import heappop as hpp, heappush as hp
for iii in range(t):
    n = int(input())
    d1 = defaultdict(list)
    d0 = defaultdict(list)
    lr = [None]*n
    for i in range(n):
        k,l,r = list(map(int, input().split()))
        lr[i] = (l,r)
        if l-r>=0:
            d1[k].append((l-r, i))
        else:
            d0[k].append((r-l, i))
            
    sl = set()
    sr = set()
    h = []
    for i in range(1,n+1):
        if i not in d1:
            continue
        for item in d1[i]:
            hp(h, item)
        while i<len(h):
            *_,ii = hpp(h)
            sr.add(ii)
    for *_,i in h:
        sl.add(i)
    h = []
    for i in range(n, 0, -1):
        if i not in d0:
            continue
        for item in d0[i]:
            hp(h,item)
        while (n-i)<len(h):
            *_,ii = hpp(h)
            sl.add(ii)
    for *_,i in h:
        sr.add(i)
    ans = 0
#     print(lr0, lr1, sl, sr)
    for i in sl:
        ans += lr[i][0]
    for i in sr:
        ans += lr[i][1]
    ANS[iii] = ans
write("\n".join(map(str, ANS)))

Measured memory_bytes: 143460
N = int(input())
T = list(map(int,input().split()))
M = int(input())
grid = []

for i in range(M):
    data = list(map(int,input().split()))
    grid.append(data)
fsum = sum(T)
for i in range(M):
##    print("gridi0="+str(grid[i][0]))
##    print("grioi1="+str(grid[i][1]))
##    print("T="+str(T[grid[i][0]-1]))
    dsum = fsum - T[grid[i][0]-1] + grid[i][1]
    print(dsum)
    





Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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 ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int a,b;
  cin  >> a >> b;
  cout << (a%3==0 || b%3==0 || (a+b)%3==0 ?"Possible" : "Impossible") << endl;
  return 0;
} 

Measured memory_bytes: 3564
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int x, y, z;
		int yn[] = new int[n];
		
		for(int i = 0; i < n; i++){
			x = scan.nextInt();
			y = scan.nextInt();
			z = scan.nextInt();
			if(x*x + y*y == z*z ||
			   x*x + z*z == y*y ||
			   y*y + z*z == x*x)yn[i] = 1;
		}
		for(int i = 0; i < n; i++){
			if(yn[i] == 1)System.out.println("YES");
			else System.out.println("NO");
		}
	}
}

Measured memory_bytes: 35008
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int n, m;
ll MOD = 1000000007;
ll a[1005], b[1005], x[1000005], y[1000005], z[1000005];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
    bool ok = true;
    cin >> n >> m;
    FOR(i, n) {
        cin >> a[i];
        if (x[a[i]] > 0) ok = false;
        x[a[i]]++;
    }
    FOR(i, m) {
        cin >> b[i];
        if (y[b[i]] > 0) ok = false;
        y[b[i]]++;
    }
    ll ret = 1;
    for (int i = n*m; i >= 1; i--) {
        int type = 3;
        if (x[i] == 1 && y[i] == 1) type = 0;
        else if (x[i] == 1) type = 1;
        else if (y[i] == 1) type = 2;
        x[i] += x[i+1];
        y[i] += y[i+1];
        z[i] = x[i] * y[i];
        if (type == 3) {
            ret = ret * (z[i] - (n*m - i)) % MOD;
        }
        else if (type == 2) {
            ret = ret * x[i] % MOD;
        }
        else if (type == 1) {
            ret = ret * y[i] % MOD;
        }
        // cout << x[i] << " " << y[i] << " " << z[i] << " " << ret << endl;
    }
    if (!ok) ret = 0;
    cout << ret % MOD << endl;
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define N 200005
#define st first
#define nd second
#define pb push_back
using namespace std;
typedef long long ll;
ll n, m, i, j, k, v[N];
bool used[N];
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}
int main()
{
    fast();
    cin>>n;
    for(i=1;i<=n;++i)
        cin>>v[i];
    i=1;
    while(i!=2)
    {
        ++k;
        if(used[i])
        {
            cout<<-1;
            return 0;
        }
        used[i]=1;
        i=v[i];
    }
    cout<<k;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define EPB emplace_back
#define MP make_pair
#define d(x) cerr << #x << ":" << x << endl;
#define da(x) cerr << #x << endl; for (auto a : x) cerr << a << " "; cerr << endl;
const int MOD = 1000000007;

int main() {
	fastio();
	ll n;
	cin >> n;
	stringstream ans;
	int corr;
	while(n) {
		corr = 0;
		if(n%26 == 0) {
			corr = -1;
			ans << "z";
		}
		else
			ans << char('a' - 1 + n%26);
		n /= 26;
		n += corr;
	}
	string res = ans.str();
	reverse(res.begin(), res.end());
	cout << res << "\n";
	return 0;
}



Measured memory_bytes: 3648
divisibleBy2 :: Int -> Int
divisibleBy2 n
  | n == 0 || n `mod` 2 /= 0 = 0
  | otherwise = succ $ divisibleBy2 (n `div` 2)

func :: Int -> Int -> [Int] -> Int
func ans _ [] = ans
func m acc (x:xs)
  | acc < count = func x count xs
  | otherwise = func m acc xs
  where
    count = divisibleBy2 x

main = do
  line <- getLine
  let
    n = read line :: Int
    ans = func 1 0 [1..n]
  putStrLn $ show ans


Measured memory_bytes: 508
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(a==b)cout<<"Draw"<<endl;
    else if(a==1&&b>1)cout<<"Alice"<<endl;
    else if(b==1&&a>1)cout<<"Bob"<<endl;
    else if(a>b)cout<<"Alice"<<endl;
    else cout<<"Bob"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mii map<int,int>
#define qi queue<int>
#define pqi priority_queue<int>
#define pqgi priority_queue<int,vector<int>,greater<int>>
#define si set<int>
#define vi vector<int>
#define vll vector<long long int>
#define vii vector<pair<int,int>>
#define mii map<int,int>
#define ii pair<int,int>
#define SYNC ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define f(i,a,b) for(int i=a;i<b;i++)
#define rf(j,c,d) for(int j=c;j>d;j--)
#define mod 1000000007
#define mo 998244353
#define inf 1e18
#define INF (int)INT_MAX
#define PI 3.1415926535898
using namespace std;
const int N=1e5+5;
/*ll po(ll A,ll B)
{
	ll RES=1;
	while(B)
	{
		if(B&1)
			RES*=A;
		B>>=1;
		A*=A;
	}
	return RES;
}*/
/*void sieve(int P)
{
	prime[0]=0;prime[1]=0;
	f(i,2,P+1)
		prime[i]=1;
	f(i,2,P+1)
	{
		if(prime[i]==1)
		{
			for(int j=i*i;j<P+1;j+=i)
			{
				prime[j]=i;
			}
		}
	}
}*/
void solve()
{
	int n;
	cin>>n;ll arr[n+4];
	f(i,0,n)
		cin>>arr[i];
	sort(arr,arr+n);
	reverse(arr,arr+n);
	ll ans=0;
	ans+=arr[0];
	int j=1;mii mp;
	f(i,1,n-1)
	{
		ans+=arr[j];
		mp[j]++;
		if(mp[j]==2)j++;
	}
	cout<<ans<<'\n';
	return;
}
int main()
{
    SYNC
    //sieve();
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
    return 0;
}

Measured memory_bytes: 9864
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        const long M = 1000000007L;

        string s = ReadLine();
        int n = s.Length;
        long[,] dp = new long[n+1, 13];
        dp[0,0] = 1;

        for (int i = 1; i <= n; i++)
        {
            char c = s[i-1];
            int x = (c == '?') ? -1 : c - '0';
            for (int j = 0; j < 10; j++)
            {
                if (x != -1 && j != x) continue;
                for (int k = 0; k < 13; k++)
                {
                    dp[i, (k * 10 + j) % 13] += dp[i-1, k];
                    dp[i, (k * 10 + j) % 13] %= M;
                }
            }
        }

        WriteLine(dp[n, 5]);
    }
}

Measured memory_bytes: 21472
#include <iostream>
#include <algorithm>
using namespace std; 
long long s[4];
int main(int argc, char** argv) {
long long a,b,c,d;
cin>>a>>b>>c>>d;
s[0]=a*c;
s[1]=a*d;
s[2]=b*c;
s[3]=b*d;
sort(s,s+4);
cout<<s[3]; 
	return 0;
}

Measured memory_bytes: 3176