akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

typedef struct {
  int a;
  char aa;
} po;


void bsort(po*,int);
void ssort(po*, int);
int sta(po*,po*,int);

int main() {
  int i,n;
  po kk[36],kkk[36];

  scanf("%d",&n);

    for(i=0;i<n;i++) {
      scanf(" %c%d",&kk[i].aa,&kk[i].a);
    }
  
    
      for(i=0;i<n;i++) {
	kkk[i].a=kk[i].a;
     	kkk[i].aa=kk[i].aa;
      }

      bsort(kk,n);
      ssort(kkk,n);

      for(i=0;i<n;i++) {
	printf("%c%d",kk[i].aa,kk[i].a);
	if(i!=n-1) printf(" ");
      }
      printf("\nStable\n");

      for(i=0;i<n;i++) {
	printf("%c%d",kkk[i].aa,kkk[i].a);
	if(i!=n-1) printf(" ");
      }
      if(sta(kk,kkk,n)) printf("\nStable\n");
      else printf("\nNot stable\n");

      return 0;
    }


void bsort(po *a,int n) {
  int i,j,p=1;
  po t;

  while(p==1){
    p=0;
    for(j=n-1;j>0;j--) {
    
      if(a[j].a<a[j-1].a) {
    
    t=a[j];
    a[j]=a[j-1];
    a[j-1]=t;
    p=1;
    
  }
}
}
}
void ssort(po *a, int n){
  int i,j,min;
  po t;

  for(i=0;i<n;i++) {
    min=i;
    for(j=i;j<n;j++) {
      if(a[j].a<a[min].a) {
	min=j;
      }
    }

    t=a[i];
    a[i]=a[min];
    a[min]=t;
  }
}


int sta(po *a, po *b, int n) {
  int i;

  for(i=0;i<n;i++) {
    if(a[i].aa!=b[i].aa)
      return 0;
  }
  return 1;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vp;
const int inf = 1e9;
const ll INF = 1e18;
const db eps = 1e-10;
const db pi = acos(-1);

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define mem(a) memset(a, 0, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(b))
#define PA cout << "pass\n"
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define TM cout << db(clock()) / CLOCKS_PER_SEC << '\n'

mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count());

template<class T>inline void upmin(T &x, T y) {x = x > y ? y : x;}
template<class T>inline void upmax(T &x, T y) {x = x < y ? y : x;}

int n, x, T;

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    cin >> n >> x >> T;
    cout << (n + x - 1) / x * T << '\n';
    return 0;
}

Measured memory_bytes: 3660
local h,w=io.read("n","n","l")
local a={}
for i=1,h do
    local input=io.read()
    a[i]={}
    for j=1,w do
        a[i][j]=input:byte(j)
    end
end

local dp={}
for i=1,h do
    dp[i]={}
    for j=1,w do
        dp[i][j]=0
    end
end
dp[1][1]=1

local mod=1000000007
for i=1,h do
    for j=1,w do
        if i<h and a[i+1][j]==46 then
            dp[i+1][j]=(dp[i+1][j]+dp[i][j])%mod
        end
        if j<w and a[i][j+1]==46 then
            dp[i][j+1]=(dp[i][j+1]+dp[i][j])%mod
        end
    end
end
print(dp[h][w])

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

int main() {
  int a, b, answer;
  cin >> a >> b;
  
  answer = a + b;
  if(a + b < a - b) answer = a - b;
  if(answer < a * b) answer = a * b;
  
  cout << answer << endl;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
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; }
using namespace std;

int H, W;
char grid[100][100];
bool vert[100], side[100];

int main(){

    cin >> H >> W;
    rep(i, H)rep(j, W){
        cin >> grid[i][j];
        if(grid[i][j] == '#'){
            vert[i] = true;
            side[j] = true;
        }
    }

    rep(i, H)if(vert[i]){
        rep(j, W)if(side[j])cout << grid[i][j];
        cout << endl;
    }

}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int x[] = new int[n];

		for (int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
		}

		Arrays.sort(x);

		int sum = 0;
		for (int i = n - 1; n - 1 - i < k; i--) {
			sum += x[i];
		}

		System.out.println(sum);


		sc.close();

	}

}

Measured memory_bytes: 35660
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	
	int counter = 0; int Max = 0;
	// bool frag = false;
	
	for (int i=0; i < S.size(); i++) {
		if (S.at(i) == 'A'||S.at(i) == 'T'||S.at(i) == 'G'||S.at(i) == 'C') {
			counter = counter +1;
			if (counter > Max) {
				Max = counter;
			}
		}
		else {
			counter = 0;
		}
	}
	
	cout << Max << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
  string S, ans;
  cin >> S;
  if (S=="Sunny") ans = "Cloudy";
  if (S=="Cloudy") ans = "Rainy";
  if (S=="Rainy") ans = "Sunny";
  cout << ans << endl;
}

Measured memory_bytes: 256
a,b,x,y,v,w,S;I(){scanf("%d%d",&x,&y);}main(i,n){for(;scanf("%d",&n)*n;S=!printf("%d %.1f\n",i++,S/2.))for(I(),a=x,b=y;n--;S+=(x-v)*(y+w))v=x,w=y,!n?x=a,y=b:I();}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    int M = N % 2 == 0 ? 2 : 3;
    vector<vector<ll>> dp(N+1,vector<ll>(M)); // dp[i][j]:空きをj個使用

    for ( int i = 1; i <= N; i++ ) {
        for ( int j = 0; j < M; j++ ) {
            if ( i > 2 ) {
                dp[i][j] = -1e15;
            } else {
                dp[i][j] = 0;
            }
        }
        for ( int j = 0; j < M; j++ ) {
            if ( i-2 >= 0 ) dp[i][j] = max(dp[i][j], dp[i-2][j]);
        }
        for ( int j = 1; j < M; j++ ) {
            if ( i-3 >= 0 ) dp[i][j] = max(dp[i][j], dp[i-3][j-1]);
        }
        for ( int j = 2; j < M; j++ ) {
            if ( i-4 >= 0 ) dp[i][j] = max(dp[i][j], dp[i-4][j-2]);
        }
        for ( int j = 0; j < M; j++ ) {
            dp[i][j] += A[i-1];
        }
    }
    ll ans = -1e15;
    for ( int j = 0; j < M; j++ ) {
        ans = max(ans, dp[N-j][M-1-j]);
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

typedef long long ll;
const int mod = 1e9 + 7;

double a, b, x;

int main() {
    cin >> a >> b >> x;
    double s = x / a;
    double all = a * b;
    double radian;
    if (s > all / 2) {
        double h = 2 * (all - s) / a;
        radian = atan2(h, a);
    } else {
        radian = atan2(b, 2 * x / all);
    }

    double deg = radian * (180 / M_PI);
    printf("%.10f\n", deg);
}

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

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class AHarmony {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int a,b;
        in>>a>>b;
        if((a+b)%2==0) out<<(a+b)/2<<endl;
        else out<<"IMPOSSIBLE"<<endl;
    }
};

int main() {
    AHarmony solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  long long ans=0;
  for(int i=0;i<(1<<n-1);i++){
    long long tmp=0;
    for(int j=0;j<n-1;j++){
      tmp*=10;
      tmp+=s[j]-'0';
      if(i&(1<<j)){
        ans+=tmp;
        tmp=0;
      }
    }
    tmp*=10;
    tmp+=s[n-1]-'0';
    ans+=tmp;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3636
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,s,x,a[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(;i++<m;)
	{
		cin>>x;
		s+=x;
	}
	cout<<(s>n?-1:n-s);
}

Measured memory_bytes: 3644
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template

# BEGIN CUT HERE
class UnionFind():
    def __init__(self,n):
        self.data = [-1] * n
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.data[x] < self.data[y]:
            x, y = y, x  # swap
        self.data[x] += self.data[y]
        self.data[y] = x
    
    def find(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.find(self.data[x])
        return self.data[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def size(self, x):
        return self.data[self.find(x)]
        
# END CUT HERE

def ABC120_D():
    n, m = mi()
    a = [0] * m
    b = [0] * m
    for i in range(m):
        a[i], b[i] = mi()
        
    uf = UnionFind(n)
    ans = [0] * (m + 1)
    ans[m] = n * (n - 1) // 2

    for i in range(m - 1, -1, -1):
        a[i] -= 1
        b[i] -= 1
        ans[i] = ans[i + 1]
        if uf.same(a[i], b[i]):
            continue
        
        x = uf.size(a[i])
        y = uf.size(b[i])
        ans[i] -= x * y
        
        uf.unite(a[i],b[i])
    
    for i in range(1, m + 1):
        print(ans[i])



if __name__ == '__main__':
    ABC120_D()


Measured memory_bytes: 288776
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    writeln(N ^^ 3);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt(), b = scanner.nextInt();
			System.out.println((a < 6) ? 0 : (a > 12) ? b : b / 2);
		}
	}
}


Measured memory_bytes: 35720
using System;

namespace ABC059B
{
    class Program
    {
        static void Main(string[] args)
        {
            string A = Console.ReadLine();
            string B = Console.ReadLine();

            if (A.Length > B.Length)
            {
                Console.WriteLine("GREATER");
                return;
            }
            if (A.Length < B.Length)
            {
                Console.WriteLine("LESS");
                return;
            }

            for (int i = 0; i < A.Length; i++)
            {
                if (A[i] > B[i])
                {
                    Console.WriteLine("GREATER");
                    return;
                }
                if (A[i] < B[i])
                {
                    Console.WriteLine("LESS");
                    return;
                }
            }

            Console.WriteLine("EQUAL");
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long X;
    cin>>X;
int ans=0;
int wer=0;
for(long long i=0;i<1000;i++)
{
    for(long long j=i*(-1);j<=i;j++)
    {if(i*i*i*i*i-j*j*j*j*j==X)
    {ans=i;wer=j;}
    
    }
}

cout<<ans<<" "<<wer<<endl;

}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

const int N = 200010;
const int INF = 1e9;
long long dp[N][5];

int cost(int j, int a) {
    if (j == 0 || j == 4) return a;
    if (j == 1 || j == 3) return a == 0 ? 2 : a % 2;
    return (a + 1) % 2;
}

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

    for (int i = 0; i < N; ++i) for (int j = 0; j < 5; ++j) dp[i][j] = INF;

    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 5; ++j) {
            for (int k = j; k < 5; ++k) {
                dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + cost(k, a[i]));
            }
        }
    }

//    for (int i = 0; i <= n; ++i) {
//        cout << "i=" << i << endl;
//        for (int j = 0; j < 5; ++j) {
//            cout << dp[i][j] << ' ';
//        }
//        cout << endl;
//    }

    long long ans = INF;
    for (int i = 0; i < 5; ++i) {
        ans = min(ans, dp[n][i]);
    }

    cout << ans << endl;
}

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

int main(){
	std::string s;
	std::cin>>s;
	int ans=0;
	int tmp=0;

	for(int i=0; i<s.size(); i++){
		if(s[i]=='A'|| s[i]=='T' || s[i]=='G' || s[i]=='C'){
			tmp++;
		}
		else{
			ans= std::max(ans, tmp);
			tmp=0;
		}
	}
	ans= std::max(ans, tmp);

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

Measured memory_bytes: 256
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args:Array[String]) = {
    var n = 0
    val b = new ArrayBuffer[Int]
    while({n=readInt;n}!=0) {
      var min = n
      for(i<-0 to 100) {
        for(j<-0 to Math.sqrt(n-i*i*i).toInt+1) {
          val m = j*j+i*i*i
          if(m>=0 && m<=n) {
            if(min > i+j+(n-m)) min = i+j+(n-m)
          }
        }
      }
      b += min
    }
    println(b.mkString("\n"))
  }
}

Measured memory_bytes: 70536
N, M = map(int, input().split())
k = []
s = []
for i in range(M):
    ki, *si = list(map(int, input().split()))
    k.append(ki)
    s.append(si)
p = list(map(int, input().split()))

ans = 0
for ptn in range(2**N):
    lamp = [False]*M
    for i in range(M):
        cnt = 0
        for j in range(k[i]):
            if (ptn>>(s[i][j]-1))&1:
                cnt += 1
        if cnt % 2 == p[i]:
            lamp[i] = True
    if all(lamp):
        ans += 1

print(ans)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<int32> pos,neg;
    REP(i,n){
        int32 a;
        cin >> a;
        if(a >= 0){
            pos.pb(a);
        }else{
            neg.pb(a);
        }
    }
    vector<pii> ans;
    int32 m;
    if(!pos.empty()){
        sort(ALL(pos));
        int32 nextx;
        if(neg.empty()){
            nextx = pos[0];
        }else if(pos.size() == 1){
            nextx = neg[0];            
        }else{
            nextx = neg[0];
            ans.pb(mp(neg[0], pos[0]));
            nextx = neg[0] - pos[0];
        }
        REP(i,(signed)pos.size()-2){
            // cout << nextx << " " << a[i+1] << "\n";
            ans.pb(mp(nextx, pos[i+1]));
            nextx -= pos[i+1];
        }
        // cout << a[n-1] << " " << nextx << "\n";
        ans.pb(mp(pos.back(), nextx));
        m = pos.back() - nextx;
        FOR(i,1,(signed)neg.size()){
            ans.pb(mp(m, neg[i]));
            m -= neg[i];
        }
    }else{
        sort(ALL(neg));
        ans.pb(mp(neg.back(), neg[0]));
        m = neg.back() - neg[0];
        FOR(i,1,(signed)neg.size()-1){
            ans.pb(mp(m, neg[i]));
            m -= neg[i];
        }
    }
    ANS(m);
    REP(i,n-1){
        int32 x,y;
        tie(x,y) = ans[i];
        cout << x << " " << y << "\n";
    }
    return 0;
}

Measured memory_bytes: 5104
#include<stdio.h>

int main()
{
 int N;
 int K;
 long x[100005];
 long dist;
 long mindist=200000005;
 long distp;
 long distm;
 int i;

 scanf("%d %d",&N,&K);
 for(i=0;i<N;i++) scanf("%ld",&x[i]);
 mindist=2*(x[N-1]-x[0]);

 for(i=K-1;i<N;i++)
 {
  if(x[i]<0) 
  {
   dist=-x[i-K+1];
  }else if(x[i-K+1]>0){
   dist=x[i];
  }else{
   distp=2*x[i]-x[i-K+1];
   distm=x[i]-2*x[i-K+1];
   if(distp<distm)
   {
    dist=distp;
   }else{
    dist=distm;
   }
  }
  if(mindist>dist) mindist=dist;
 }
 printf("%ld\n",mindist);
 return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k, s;

void solve() {
    for (int i = 0; i < k; i++)
        cout << s << " ";
    for (int i = 0; i < n-k; i++)
        cout << (s==(int)1e9 ? 1 : (int)1e9) << " ";
    cout << endl;
}

void input() {
    cin >> n >> k >> s;
}

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

    input();
    solve();
}


Measured memory_bytes: 1280
import sys
# sys.stdin = open('input.txt')

k,n = map(int, input().split())
a = list(map(int, input().split()))

left = a[n-1] - a[0]
right = k + 1

for i in range(n):
    if i == n-1:
        tmp = k - (a[0] + (k - a[i]))
    else:
        tmp = k - (a[i+1] - a[i])
    right = min(right, tmp)

print(min(left, right))

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

const double eps = 1e-9;

struct Task {
	int n, m;
	vector<vector<int>> g;

	Task(int n, int m): n(n), m(m), g(n) {
		for (int i = 0; i < m; ++i) {
			int x, y;
			cin >> x >> y;
			--x; --y;
			g[x].push_back(y);
			g[y].push_back(x);
		}
	}

	void dfs(int v, vector<int>& color, vector<int>& was, int& bipartite, int& size) {
		was[v] = 1;
		++size;
		for (auto& to : g[v]) {
			if (!was[to]) {
				color[to] = color[v] ^ 1;
				dfs(to, color, was, bipartite, size);
			} else {
				if (color[to] == color[v]) {
					bipartite = false;
				}
			}
		}
	}

	void run() {
		vector<int> color(n);
		vector<int> was(n);
		int curColor = 0;

		int all = 0;
		int comp = 0, bcomp = 0;
		long long result = 1LL * n * n;

		for (int i = 0; i < n; ++i) {
			if (!was[i]) {
				int size = 0;
				int bipartite = 1;
				dfs(i, color, was, bipartite, size);

				if (size == 1) {
					continue;
				}

				result -= 2LL * all * size - 2LL * (comp + (bipartite ? bcomp : 0));
				result -= 1LL * size * size - 1 - bipartite;

				all += size;
				++comp;
				bcomp += bipartite;

			}
		}
		cout << result << '\n';
	}
};

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

	int t = 1;
	while (t--) {
		int n, m;
		cin >> n >> m;
		Task test(n, m);
		test.run();
	}
	return 0;
}

Measured memory_bytes: 9472
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        
        static void Solve()
        {
            var o = ReadAndParseIntArr();
            int a = o[0];
            int b = o[1];
            int c = o[2];

            string ans = null;
            if( a+b==c || a+c==b || b+c==a)
            {
                ans = "Yes";
            }
            else
            {
                ans = "No";
            }
            Console.WriteLine(ans);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    for (int i = L; i <= R; i++) {
        if (i%d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
N = int(input())

ans = 0
for n in range(1, N+1, 1):
    count = 0
    if n%2==0:
        continue
    for i in range(1, int(n**0.5)+1):
        if n%i==0:  
            count = count + 2
    if count==8:
        ans = ans + 1

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;

int ds(int n)
{
    int s = 0;
    while (n > 0) {
        s += n % 10;
        n /= 10;
    }
    return (s);
}

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

    int N;
    cin >> N;
    int minv = 1 << 30;

    for (int i=1; i < N; ++i) {
        int j = N - i;
        minv = min(minv, ds(i) + ds(j));
    }

    outl(minv);
}



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

int main() {
  int n;
  cin>>n;
  
  vector<int> data(n);
  for (int i=0;i<n;i++){
    cin>>data.at(i);
  }
  
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  

  int answer=1;
  
  for (int i=1;i<n;i++){
    if (data.at(i)<data.at(i-1)){
      answer+=1;
    }
  }

  cout<<answer<<endl;
       
    

  
  
}

  













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

int main() {
  int N; cin >> N;
  long long a[50];
  int p = 0;
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
    if(abs(a[p]) < abs(a[i])) {
      p = i;
    }
  }

  cout << 2 * N - 1 << endl;
  for(int i = 0; i < N; ++i) {
    cout << p + 1 << " " << i + 1 << endl;
  }
  if(a[p] < 0) {
    for(int i = N; i > 1; --i) {
      cout << i << " " << i - 1 << endl;
    }
  } else {
    for(int i = 1; i < N; ++i) {
      cout << i << " " << i + 1 << endl;
    }
  }
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from fractions import gcd

class Dinic:
    class Edge:
        def __init__(self, to, cap, rev):
            self.to = to
            self.cap = cap
            self.rev = rev
        
        def __repr__(self):
            return "(to: {0} cap: {1} rev: {2})".format(self.to, self.cap, self. rev)

    def __init__(self,V):
        self.V = V
        self.size = [0 for i in range(V)]
        self.G = [[] for i in range(V)]

    def add_edge(self, _from, to, cap):
        self.G[_from].append(self.Edge(to, cap, self.size[to]))
        self.G[to].append(self.Edge(_from, 0, self.size[_from]))
        self.size[_from] += 1
        self.size[to] += 1

    def bfs(self,s):
        level = [-1 for i in range(self.V)]
        level[s] = 0
        q = []
        q.append(s)
        while q != []:
            v = q.pop(0)
            for u in self.G[v]:
                if u.cap > 0 and level[u.to] < 0:
                    level[u.to] = level[v] + 1
                    q.append(u.to)
        return level

    def dfs(self, v, t, f):
        if v == t: return f
        for i in range(self.iterator[v],self.size[v]):
            self.iterator[v] = i
            edge = self.G[v][i]
            if edge.cap > 0 and self.level[v] < self.level[edge.to]:
                d = self.dfs(edge.to, t, f if f < edge.cap else edge.cap)
                if d > 0:
                    self.G[v][i].cap -= d
                    self.G[edge.to][edge.rev].cap += d
                    return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.level = self.bfs(s)
            if self.level[t] < 0:
                return flow
            self.iterator = [0 for i in range(self.V)]
            while True:
                f = self.dfs(s, t, float('inf'))
                if f == 0:
                    break
                flow += f

while True:
    m,n = map(int,input().split())
    if (m,n) == (0,0):
        break
    B = []
    R = []

    while True:
        for x in map(int, input().split()):
            B.append(x)
        if len(B) ==m:
            break

    while True:
        for x in map(int, input().split()):
            R.append(x)
        if len(R) == n:
            break
    dinic = Dinic(2 + m + n)
    
    _b = 1
    _r = 1 + m
    for b_idx, b in enumerate(B):
        for r_idx, r in enumerate(R):
            if gcd(b,r) > 1:
                dinic.add_edge(_b + b_idx, _r + r_idx, 1)
        dinic.add_edge(0, b_idx + _b, 1)
    for r_idx, r in enumerate(R):
        dinic.add_edge(r_idx + _r, 1 + m + n, 1)
    dinic.max_flow(0, 1+m+n)
    ans = 0
    for rev in dinic.G[1+m+n]:
        ans += rev.cap
    print(ans)

Measured memory_bytes: 57540
n = int(input())
con = [set() for _ in range(n)]
tree = [0]*n

for _ in range(n-1):
    a,b = map(int,input().split())
    con[a-1].add(b)
    con[b-1].add(a)

checked = set([1])
stack = list(con[0])
stack_ = []
while len(checked) < n:
    while stack:
        x = stack.pop()
        if x in checked:
            continue
        checked.add(x)
        stack_.extend(con[x-1])
        tree[x-1] = 1
        
    while stack_:
        x = stack_.pop()
        if x in checked:
            continue
        checked.add(x)
        stack.extend(con[x-1])

mod0 = []
mod1 = []
mod2 = []
for i in range(n):
    if (i+1)%3 == 0:
        mod0.append(i+1)
    elif (i+1)%3 == 1:
        mod1.append(i+1)
    else:
        mod2.append(i+1)

ans = [0]*n
sum_tree = sum(tree)
if sum_tree < n/3:
    for i in range(n):
        if tree[i] == 0:
            if mod1:
                ans[i] = mod1.pop()
            elif mod2:
                ans[i] = mod2.pop()
            else:
                ans[i] = mod0.pop()
        else:
            ans[i] = mod0.pop()
elif sum_tree > n*2/3:
    for i in range(n):
        if tree[i] == 1:
            if mod1:
                ans[i] = mod1.pop()
            elif mod2:
                ans[i] = mod2.pop()
            else:
                ans[i] = mod0.pop()
        else:
            ans[i] = mod0.pop() 
else:
    for i in range(n):
        if tree[i] == 0:
            if mod1:
                ans[i] = mod1.pop()
            else:
                ans[i] = mod0.pop()
        else:
            if mod2:
                ans[i] = mod2.pop()
            else:
                ans[i] = mod0.pop()
            
print(" ".join(map(lambda x:str(x), ans)))

Measured memory_bytes: 100360
function Main(input){
    i=input.split("\n");
    n=Number(i[0]);
    i.shift();
    b=[];
    sum=0
    for(a=0;a<i.length;a++){
        b.push(i[a].split(" "))
    }
    for(c=0;c<b.length;c++){
        if(b[c][1]==="BTC")sum+=Number(b[c][0])*380000
        else sum+=Number(b[c][0])
    }
    console.log(sum)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 23112
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string str;
int n,b,r;
cin>>n>>b>>r;
int x=b+r;
int ans=(n/x)*b;
ans+=min(b,n%x);
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define cmax(a,b) a=max(a,b)
using namespace std;
int Q=0;
namespace GRD
{
	const int N=135;
	string s;
	void init()
	{
		freopen("a.in","r",stdin);
		cin>>s;
	}
	int dp[N][N];
	int qry(string t)
	{
		Q++;
		int i,j,n,m,ans=0;
		n=s.length();m=t.length();
		memset(dp,-1,sizeof(dp));
		dp[0][0]=0;
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=m;j++)
			{
				if(dp[i][j]==-1) continue;
				cmax(ans,dp[i][j]);
				if(i<n&&j<m&&s[i]==t[j]) cmax(dp[i+1][j+1],dp[i][j]+1);
				if(i<n) cmax(dp[i+1][j],dp[i][j]);
				if(j<m) cmax(dp[i][j+1],dp[i][j]);
			}
		}
		return max(n,m)-ans;
	}
}
int qry(string s)
{
	int ret;
	printf("? %s\n",s.c_str());
	fflush(stdout);
	scanf("%d",&ret);
	return ret;
}
struct Node
{
	string w;
	int c;
	bool operator <(const Node &a)const
	{
		return c>a.c;
	}
};
priority_queue<Node> prq;
int main()
{
	int i,j,num,t1,t2,len=0;
	string s,t;
	Node a,b;
	char cw;
	for(i=0;i<62;i++)
	{
		s="";
		if(i<26) cw='a'+i;
		else if(i<52) cw='A'+(i-26);
		else cw='0'+(i-52);
		for(j=0;j<128;j++) s+=cw;
		num=128-qry(s);
		len+=num;
		if(num==0) continue;
		s="";
		for(j=0;j<num;j++) s+=cw;
		prq.push((Node){s,num});
	}
	while(prq.size()>=2)
	{
		a=prq.top();prq.pop();
		b=prq.top();prq.pop();
		s="";
		t1=t2=0;
		for(i=1;i<=a.c+b.c;i++)
		{
			if(t1<a.c&&t2<b.c)
			{
				t=s+a.w[t1];
				for(j=t2;j<b.c;j++) t+=b.w[j];
				if(len-qry(t)==i+(b.c-t2)) s+=a.w[t1++];
				else s+=b.w[t2++];
			}
			else
			{
				if(t1==a.c) s+=b.w[t2++];
				else s+=a.w[t1++];
			}
		}
		prq.push((Node){s,a.c+b.c});
	}
	a=prq.top();
	printf("! %s\n",a.w.c_str());
	fflush(stdout);
	//printf("Query num %d\n",Q);
	return 0;
}

Measured memory_bytes: 3800
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,max,ans;
	scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
	if(a<40){
		a=40;
	}
	if(b<40){
		b=40;
	}
	if(c<40){
		c=40;
	}
	if(d<40){
		d=40;
	}
	if(e<40){
		e=40;
	}
	max=a+b+c+d+e;
	ans=max/5;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 2756
//AtCoder-agc003D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template <typename _Tp> inline void read(_Tp&x){
    char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
    while(isdigit(c11))x=x*10+c11-'0',c11=getchar();
}

const ll MX=1e10;
const int N=101000,M=2400;
ll a[N],bs[N];
int is[M],pri[M];
int n,ans,tot,tp;
bool t1=false;

map <ll,int> mp;

inline ll pw3(ll x){return x*x*x;}

inline ll f(ll x){
    ll res(1ll);
    for(int i=1;i<=tp&&pri[i]<=x;++i){
        int t=0;
        while(x%pri[i]==0)
            x/=pri[i],++t;
        if(t==1)res*=pri[i]*pri[i];
        else if(t==2)res*=pri[i];
    }
    if(x==1)return res;
    ll sqr=sqrt(x);
    if(sqr*sqr==x)return res*sqr;
    else if(res*x*x<=MX)return res*x*x;
    else return -1;
}

int main(){
    read(n);
    for(int i=1;i<=n;++i)read(a[i]);
    for(int i=2;i<=2200;++i){
        if(!is[i])pri[++tp]=i;
        for(int j=1;j<=tp&&i*pri[j]<=2200;++j){
            is[i*pri[j]]=1;
            if(i%pri[j]==0)break;
        }
    }
    for(int i=1;i<=tp&&pw3(pri[i])<=MX;++i)
        bs[++tot]=pw3(pri[i]);
    for(int i=1;i<=n;++i){
        for(int j=1;j<=tot&&bs[j]<=a[i];++j)
            while(a[i]%bs[j]==0)a[i]/=bs[j];
        if(a[i]==1)t1=true;
        else ++mp[a[i]];
    }
    sort(a+1,a+n+1);
    int i=1;
    while(a[i]==1&&i<=n)++i;
    for(int las;(las=i)<=n;++i){
        while(a[i]==a[i+1])++i;
        ll tar=f(a[i]);
        if(tar==-1)ans+=i-las+1;
        else if(tar<a[i]&&(*lower_bound(a+1,a+n+1,tar))==tar)continue;
        else ans+=max(i-las+1,mp[tar]);
    }
    printf("%d\n",ans+t1);
    return 0;
}

Measured memory_bytes: 11264
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, K; cin >> N >> K;
    vl A(N);
    rep(i, N){
        cin >> A[i]; A[i]--;
    }
    vl S(N+1, 0);
    rep(i, N) S[i+1] = (A[i] + S[i])%K;
    ll idx = 0; ll ans = 0;
    map<ll, ll> m;
    rep(i, min(K, N+1)) m[S[i]]++;
    while(idx < N){
//        cerr << m[S[idx]]-1 << endstr;
        ans += m[S[idx]]-1;
        if(idx+K <= N) m[S[idx+K]]++;
        m[S[idx]]--;
        idx++;
    }
    cout << ans << endstr;
    return 0;
}


Measured memory_bytes: 15872
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<long long> v;
    int n;
    cin>>n;
    if(n==1){
        cout<<"Yes"<<endl;
        return 0;
    }
    for(int t=0;t<n;t++){
        long long tmp;
        cin>>tmp;
        v.push_back(tmp);
    }
    for(int i=1;i<n;i++){
        if(v[i-1]>v[i]){
            v[i]++;
            if(v[i-1]>v[i]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
static const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q,key;
string s,sb;
bool ok;

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

  cin>>n; Int sum[n+1]={},xo[n+1]={};
	rep(i,n){cin>>x; sum[i+1]=sum[i]+x; xo[i+1]=xo[i]^x;}
	int r=1; Int ans=0;
	rep(l,n){
		for(;sum[r]-sum[l]==(xo[r]^xo[l])&&r<=n;r++);
		ans+=r-l-1;
	}
	END
}

Measured memory_bytes: 3328
N, M = map(int, input().split())

S = [0] * M
C = [0] * M

for i in range(M):
    s, c = map(int, input().split())
    S[i] = s - 1
    C[i] = c

def ok(x):
    X = str(x)
    for i in range(M):
        # print(S[i], C[i])
        # print(len(X) >= S[i], int(X[S[i]]) != C[i])
        if len(X) <= S[i]:
            return False
        if int(X[S[i]]) != C[i]:
            return False

    return len(X) == N

def pr():
    for i in range(1000):
        if ok(i):
            print(i)
            return
    print(-1)

pr()

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 kk, xx;
	cin >> kk >> xx;
	cout << (500 * kk >= xx ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
map <int , int> freq;
int n;

int main() {
   scanf("%d" , &n);
   for (int i = 0 ; i < n ; i++) {
      int u; scanf("%d" , &u);
      freq[u]++;
   }
   bool distinct = true;
   for (auto it = freq.begin() ; it != freq.end() ; it++) {
      if ((*it).second > 1) {
         distinct = false;
      }
   }
   printf(distinct ? "YES\n" : "NO\n");
}


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

int main() {
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a.at(i);
    }
    int max_num = k - a.at(n-1) + a.at(0);
    for(int i = 1; i < n; i++){
        max_num = max(max_num , a.at(i) - a.at(i-1));
    }
    cout << k - max_num << endl;
}


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

int main(){

    string str;
    getline(cin,str);
    for(int i= 0;i<(int)str.size();i++){
        if( islower(str[i])){
          str[i] = toupper(str[i]);
         } else if( isupper(str[i]) ){
           str[i]=tolower(str[i]);
         }
     }
     cout<<str<<endl;
     return 0;
}


Measured memory_bytes: 3140
n=int(input())
s=input()
ans=s
s+='#'

c=s.count('()')
while c!=0:
  s=list(s)

  i=0
  n_s=''
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      i+=2
    else:
      n_s+=s[i]
      i+=1

  s=''.join(n_s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define ll long long

ll knapsack(ll v[],ll w[],ll W,ll n)
{
	ll dp[n+1][W+1];
	for(ll i=0;i<=n;i++)
	{
		for(ll j=0;j<=W;j++)
		{
			if(i==0 || j==0) dp[i][j]=0;
			else if(j>=w[i-1]) dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
			else dp[i][j]=dp[i-1][j];
		}
	}
	return dp[n][W];
}

int main()
{
	ll n,W;
	cin>>n>>W;
	ll v[n],w[n];
	for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
	cout<<knapsack(v,w,W,n)<<"\n";
	return 0;
}


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

using namespace std;

#define debug(x) cerr << endl << "DEBUG: (" << (#x) << " = " << x << ")" << endl;
#define debugArray(v) for (auto i : v) cerr << i << " "; cerr << endl;

const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const long long INFLL = 0x3f3f3f3f3f3f3f3fLL;
const long double EPS = 1e-9;
const long double PI = acos(-1.0);

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n;

    cin >> n;

    long long ans = 0;

    for (long long i = 1; i <= n; i++) {
        long long m = n / i;
        ans += i * (m * (m + 1)) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin>>N;
    vector<int> h(N);
    for(int i=0;i<N;i++) cin>>h[i];

    int ans=0,cur=0;
    for(int i=1;i<N;i++){
        if(h[i-1]>=h[i]){
            cur++;
            ans=max(ans,cur);
        }else{
            cur=0;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int a, b;
	cin >> a >> b;
	int ans = a * b / __gcd(a, b);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  map<char, int> m;
  for (char c : s) {
    m[c]++;
  }
  auto isvalid = [&]() {
    if (m.size() != 2) {
      return false;
    }
    for (auto p : m) {
      if (p.second != 2) {
        return false;
      }
    }
    return true;
  };
  if (isvalid()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:102400000,102400000")
#include<iostream>  
#include<cstdio>  
#include<fstream>  
#include<iomanip>
#include<algorithm>  
#include<cmath>  
#include<deque>  
#include<vector>  
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include<queue>  
#include<string>  
#include<cstring>  
#include<map>  
#include<stack>  
#include<set>
#include<functional>
#define pb push_back
#define pii pair<int, int>
#define mod 1000000007
#define mp make_pair
#define pi acos(-1)
#define eps 0.00000001
#define mst(a,i) memset(a,i,sizeof(a))
#define fore(i,fa,fb) for(i=fa;i<=fb;++i)
#define bfore(i,fa,fb) for(i=fb;i>=fa;--i)
#define all(n) (n.begin(),n.end())
#define F first
#define S second
#define inf 0x3f3f3f3f
typedef long long ll;
using namespace std;
const int maxn = 1e4;
int maxalp[26];
int alp[26];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int i, j, k, m, n;
	for (i = 0; i <= 25; ++i)maxalp[i] = inf;
	cin >> n;
	fore(i, 1, n)
	{
		mst(alp, 0);
		string a;
		cin >> a;
		for (j = 0; j < a.size(); ++j)
		{
			++alp[a[j] - 'a'];
		}
		for (j = 0; j <= 25; ++j)
			maxalp[j] = min(maxalp[j], alp[j]);
	}
	for (i = 0; i <= 25; ++i)
	{
		if (maxalp[i] == inf)continue;
		for (j = 1; j <= maxalp[i]; ++j)
			cout << char('a' + i);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	k, _ := strconv.Atoi(Scanner())
	xs := make([]int, n)
	ys := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i], _ = strconv.Atoi(Scanner())
		ys[i], _ = strconv.Atoi(Scanner())
	}
	sorted_xs := make([]int, n)
	sorted_ys := make([]int, n)
	copy(sorted_xs, xs)
	copy(sorted_ys, ys)
	sort.Ints(sorted_xs)
	sort.Ints(sorted_ys)
	ans := 4000000000000000000
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for p := 0; p < n; p++ {
				for l := p + 1; l < n; l++ {
					c := 0
					for m := 0; m < n; m++ {
						if xs[m] >= sorted_xs[i] && xs[m] <= sorted_xs[j] && ys[m] >= sorted_ys[p] && ys[m] <= sorted_ys[l] {
							c++
						}
					}
					if c >= k {
						s := (sorted_xs[j] - sorted_xs[i]) * (sorted_ys[l] - sorted_ys[p])
						if s == 0 {
							ans = smaller(ans, smaller((sorted_xs[j]-sorted_xs[i]), (sorted_ys[l]-sorted_ys[p])))
						} else {
							ans = smaller(ans, s)
						}
					}
				}
			}
		}
	}
	fmt.Println(larger(ans, 1))
}
func smaller(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}
func larger(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpii = vector<pll>;

int main(){
  ll N, K, X, Y;
  cin >> N >> K >> X >> Y;

  ll ans = 0;

  if(N <= K){
    ans = N * X;
  } else{
    ans = K * X + (N - K) * Y;
  }

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie();cout.tie();
	ll n,T;
	cin>>n>>T;
	while(T--)
	{
		ll l,w;
		cin>>l>>w;
		if(n!=1){
			ll father=0;
			l--;w--;
			while(l>0){
				while(w>l){
					int t=w/n;
					
					if(w%n==0)
						t--;
					w=t;
				}
				if(w==l){
					father=w;
					break;
				}
				int x=l/n;
				if(l%n==0)
					x--;
				l=x;
			}
			cout<<father+1<<endl;
		}
		else 
		cout<<l<<endl;
	}
	return 0;
}

Measured memory_bytes: 1280
n = gets.to_i
as = gets.chomp.split.map(&:to_i)
MOD = 10**9+7
sum = 0
num_lcm = 1
as.each do |a|
  num_lcm = num_lcm.lcm(a)
end
as.each do |a|
  sum += num_lcm / a
end
puts sum % MOD


Measured memory_bytes: 63400
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(void) {
	int N;
	scanf("%d", &N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int l, r;
		scanf("%d %d", &l, &r);
		ans += r - l + 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3824