akhauriyash/Code-Regression huggingface dataset:
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if(s == "Sunny")  cout << "Cloudy" << endl;
  if(s == "Cloudy") cout << "Rainy"  << endl;
  if(s == "Rainy")  cout << "Sunny"  << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e18;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt[1000005];
int gcd(int X,int Y) {
    if(X%Y == 0) {
        return Y;
    }
    else {
        return gcd(Y,X%Y);
    }
}
signed main() {
    vector<int> is_prime(1005,1);
    is_prime[0] = 0;is_prime[1] = 0;
    for (int i = 2; i <= 1000; i++) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < 1000; j+=i) is_prime[j] = 0;
    }
    set<int>prime;
    for(int i = 1; i <= 1000; i++) {
        if(is_prime[i] == 1) {
            prime.insert(i);
        }
    }
    int N;
    cin >> N;
    vector<int>A(N);
    int GCD = 0;
    bool ok = true;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        if(i == 0) {
            GCD = A[i];
        }
        GCD = gcd(GCD,A[i]);
    }
    for(int i = 0; i < N; i++) {
        int X = A[i];
        for(int j:prime) {
            if(j*j > A[i]) {
                break;
            }
            if(X%j == 0) {
                if(cnt[j] >= 2) {
                    ok = false;
                    goto END;
                }
                cnt[j]++;
                while (X%j == 0) {
                    X/=j;
                }
            }
        }
        if(X >= 2) {
            cnt[X]++;
            if(cnt[X] >= 2) {
                ok = false;
                goto END;
            }
        }
    }
    for(int i = 1; i <= 1000000; i++) {
        if(cnt[i] >= 2) {
            ok = false;
        }
    }
END:;
    if(ok) {
        cout << "pairwise coprime" << endl;
    }
    else if(GCD == 1) {
        cout << "setwise coprime" << endl;
    }
    else {
        cout << "not coprime" << endl;
    }
}


Measured memory_bytes: 11824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define all1(i) begin(i),end(i)
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,a,b,M=0;
    vector<ll> A,B,As(214514,0),Bs(214514,0);
    
    cin >> N;
    REP(i,N){cin >> a;M=max(M,a+1);A.push_back(a);As[a]++;}
    REP(i,N){cin >> b;M=max(M,b+1);B.push_back(b);Bs[b]++;}
    
    REP(i,M){
        if(As[i]+Bs[i]>N){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    
    reverse(B.begin(),B.end());
    
    //この時点でかぶってるのは一つの区間のみ
    ll T=-1;
    REP(i,N){
        if(A[i]==B[i]){
            T=A[i];
            break;
        }
    }
    
    //かぶりがないのでオワオワリ
    if(T==-1){
        REP(i,N){
            cout << B[i];
            if(i==N-1){cout << endl;}else{cout << " ";}
        }
        return 0;
    }
    
    
    //以降かぶりがある
    //Bのかぶりを先頭にうつしちゃう
    vector<ll> C;
    REP(i,N){
        if(B[i]==T && A[i]<=T){
            C.push_back(B[i]);
            B[i]=INF;
        }
    }
    REP(i,N){
        if(B[i]!=INF){
            C.push_back(B[i]);
        }
    }
    B=C;
    
    //REP(i,N){cout << B[i] << " ";}cout << Endl;
    
    ll ia=N-1;
    REP(i,N){
        if(A[i]==B[i]){
            swap(A[ia],A[i]);
            ia--;
        }
    }
    
    vector<pair<ll,ll>> Ans;
    REP(i,N){
        Ans.push_back({A[i],B[i]});
        if(A[i]==B[i]){
            assert(false);
        }
    }
    sort(Ans.begin(),Ans.end());
    
    REP(i,N){
        cout << Ans[i].second;
        if(i==N-1){cout << endl;}else{cout << " ";}
    }
    
    
    return 0;
}



Measured memory_bytes: 15460
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Measured memory_bytes: 173832
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
int n;
int c;
int d[100][100];
int gs[3][50];
int tu[550][550];
int main()
{
    cin>>n>>c;
    for(int i=1;i<=c;i++)
    for(int j=1;j<=c;j++)cin>>d[i][j];
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)cin>>tu[i][j];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            gs[(i+j)%3][tu[i][j]]++;
        }
    }
    int ans=inf;
    for(int x=1;x<=c;x++)
    for(int y=1;y<=c;y++)
    for(int z=1;z<=c;z++){
        if(x==y||x==z||y==z)continue;
        int temp=0;
        for(int i=1;i<=c;i++){
            temp+=d[i][x]*gs[0][i];
            temp+=d[i][y]*gs[1][i];
            temp+=d[i][z]*gs[2][i];
        }
        ans=min(ans,temp);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

const int MAX_N=50;
int par[MAX_N]; //親の番号
int height[MAX_N]; //木の高さ(ランク)

//初期化
void init(int n){
  REP(i, n){
    par[i] = i;
    height[i] = 0;
  }
}

//xの親番号を返す、再帰処理あり
int root(int x){
  return par[x] == x ? x : par[x] = root(par[x]);
}

//xとyの親番号が同一か判定する
bool same(int x, int y){
  return root(x) == root(y);
}

//xとyのある木を結合する
void unite(int x, int y){
  x = root(x);
  y = root(y);
  if(x == y) return; //親が同一なら結合済み。

  if(height[x] < height[y]) par[x] = y;
  else {
    par[y] = x;
    if(height[x] == height[y]) height[x]++;
  }
}

int main(){
  int N, M;
  cin >> N >> M;
  init(N);
  pair<int, int> node[M];
  REP(i, M) {
    cin >> node[i].first >> node[i].second;
  }

  int count=0;
  REP(i, M){
    REP(j, M){
      if(j == i) continue;
      else{
        unite(node[j].first-1, node[j].second-1);
      }
    }
    for(int j=1; j<N; ++j){
      if(same(0, j) == false) {
        ++count;
        goto loopend;
      }
    }

    loopend:
    init(N);
  }

  cout << count <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)


//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N;
    while(cin>>N, N){
        vector<string> ss(N);
        
        for(auto &s: ss)
            cin >> s;
        
        for(int i=0; i<N; i++){
            string &s = ss[i];
            int j = 0;
            while(s[j]=='.') s[j++] = ' ';
           
            if(j<1) continue;
            s[j-1] = '+';
            int idx = i;
            while(idx>=0 && ss[--idx][j-1]==' ') ss[idx][j-1] = '|';
            
        }
        
        
        for(auto &s: ss)
            cout << s << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1788
import numpy as np
import sys
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
arr = sorted(a, key = lambda x:x[1])
#print(arr)
#arr = np.array(a)
#arr_sort = np.sort(arr, axis=0)
#print(arr_sort)

tmp = 0
for i in range(n) :
    tmp += arr[i][0]
    if tmp > arr[i][1] :
        print('No')
        sys.exit()

print('Yes')

Measured memory_bytes: 64248
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,fl=0 ; cin>>a>>b>>c ;
    for(int x=1 ; x<=100000 ; x++)
    {
        if((b*x+c)%a==0) {fl=1 ; break ;}
    }
    if(fl) cout<<"YES"<<endl ;
    else cout<<"NO"<<endl ;
}


Measured memory_bytes: 3564
import java.util.Scanner;

//JOI and IOI
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			char[] s = sc.next().toCharArray();
			int c = 0;
			int d = 0;
			for(int i=2;i<s.length;i++){
				if(s[i]=='I'&&s[i-1]=='O'){
					c+=s[i-2]=='J'?1:0;
					d+=s[i-2]=='I'?1:0;
				}
			}
			System.out.println(c+"\n"+d);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

#define ll long long
#define mx  3000005
#define mod 1000000007
#define lim 100

using namespace std;


int main() {
	ios_base ::sync_with_stdio(false);

     int half;
     string s;cin>>half>>s;

     map<pair<string,string>,int>mp;

     for(int aps=0;aps<1<<half;aps++)
	{
		string r="",b="";

		for(int i=0;i<half;i++)
		{
			if(aps>>i & 1)
			{
				r+=s[i];
			}
		}

		for(int i=half-1;i>=0;i--)
		{
			if(!(aps>>i & 1))
			{
				b+=s[i];
			}
		}
		mp[make_pair(r,b)]++;
	}

	ll ans=0;
	for(int aps=0;aps<1<<half;aps++)
	{
		string r="",b="";

		for(int i=0;i<half;i++)
		{
			if(aps>>i & 1)
			{
				r+=s[half+i];
			}
		}

		for(int i=half-1;i>=0;i--)
		{
			if(!(aps>>i & 1))
			{
				b+=s[half+i];
			}
		}
		ans+=mp[make_pair(b,r)]*1LL;
	}

	cout<<ans<<"\n";

     return 0;
}


Measured memory_bytes: 91904
n = input()
n = input()
nl = list(n)
w = [0 for i in range(len(n))]
e = [0 for i in range(len(n))]
w[0] = 1 if nl[0] == "W" else 0
e[0] = 1 if nl[0] == "E" else 0
for i in range(len(n)-1):
    w[i+1] = w[i] + 1 if nl[i+1] == "W" else w[i]
    e[i+1] = e[i] + 1 if nl[i+1] == "E" else e[i]
wr = [0 for i in range(len(n))]
er = [0 for i in range(len(n))]
ans = [0 for i in range(len(n))]
for i in range(len(n)):
    wr[i] = w[len(n)-1] - w[i]
    er[i] = e[len(n)-1] - e[i]
for i in range(len(n)):
    temp = w[i] - 1 if nl[i] == "W" else w[i]
    ans[i] = temp + er[i]
# print(w)
# print(e)
# print(wr)
# print(er)
# print(ans)
print(min(ans))

Measured memory_bytes: 55756
import sys, math
def input():
    return sys.stdin.readline()[:-1]
from itertools import permutations, combinations
from collections import defaultdict, Counter
from math import factorial
from bisect import bisect_left # bisect_left(list, value)
#from fractions import gcd
enu = enumerate

sys.setrecursionlimit(10**7)
S = input()

if S == 'AAA' or S=='BBB':
    print('No')
else:
    print('Yes')


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

#define endl '\n'
#define PB push_back
#define PF push_front
#define MP make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 1e9 + 7;
const ll LINF = 1e18 + 14;

int main(){
    ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    int d, t, s;
    cin >> d >> t >> s;
    if (d <= t * s) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
} 


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<stdio.h>
    
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007
    
using namespace std;
    
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;
    

ll mult(ll a, ll b){
    ll mod_a = a%MOD;
    ll mod_b = b%MOD;

    return (mod_a * mod_b)%MOD;
}


ll som(ll a, ll b){
    ll mod_a = a%MOD;
    ll mod_b = b%MOD;
    
    return (mod_a + mod_b)%MOD;
}


int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);
    
    ll N;
    ll soma_total = 0;
       
    cin>>N;

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

    ll somatorio_produtos = 0;
    for(int i = 0; i<N; ++i){
        soma_total-=A[i];
        somatorio_produtos = som(somatorio_produtos, mult(A[i], soma_total));
    }

    cout<<somatorio_produtos<<endl;

    return 0;   
}

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

int n,m,tsum,hsum,minn,at,ah;
vector<int> ta,ha;

int main(){
  int i,j,k;
  while(1){
    cin >> n >> m;
    if(n+m==0)break;
    tsum=0;
    hsum=0;
    minn=9999999;
    at = -1;
    ah = -1;
    for(i=0;i<n;i++){
      cin >> j;
      ta.push_back(j);
      tsum+=j;
    }
    for(i=0;i<m;i++){
      cin >> j;
      ha.push_back(j);
      hsum+=j;
    }
    if(abs(hsum-tsum)%2==0){
      for(i=0;i<n;i++)for(j=0;j<m;j++){
	  if((tsum-hsum)/2==(ta[i]-ha[j])&&minn>abs(ta[i]-ha[j])){
	    at = ta[i];
	    ah = ha[j];
	    minn = abs(at-ah);
	  }
	}
    }
    //cout << "ans ";
    if(at+ah!=-2)cout << at << " "<<ah <<endl;
    else cout << -1 << endl;
    while(ha.size())ha.pop_back();
    while(ta.size())ta.pop_back();
  }
  return 0;
}



Measured memory_bytes: 3052
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;


int main() {
    string A, B;
    cin >> A;
    cin >> B;

    if (A.size() >= B.size() && A > B) {
        cout << "GREATER" << endl;
    } else if (A == B) {
        cout << "EQUAL" << endl;
    } else {
        cout << "LESS" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	int N,M,K;
	cin>>N>>M>>K;
	
	combi C(N*M);
	
	int x = 0;
	
	for(int i=1;i<=N-1;i++){
		int a = mod((N-i)*M);
		a = mod(a*M);
		a = mod(a*i);
		x = mod(x+a);
	}
	//cout<<x<<endl;
	
	x = mod(x * C.combination(N*M-2,K-2));

	
	int y = 0;
	for(int i=1;i<=M-1;i++){
		int a = mod((M-i)*N);
		a = mod(a*N);
		a = mod(a*i);
		y = mod(y+a);
	}
	
	y = mod(y*C.combination(N*M-2,K-2));
	

	
	cout<<mod(x+y)<<endl;
		
	
	return 0;
	
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <string.h>

int main(void){
    int n;
    int i = 0;
    int ACcount = 0;
    int WAcount = 0;
    int TLEcount = 0;
    int REcount = 0;
    char str[3];
    scanf("%d", &n);
    while(i < n){
        scanf("%s", str);
        if(str[0] == 'A' && str[1] == 'C'){
            ACcount++;
        }else if(str[0] == 'W' && str[1] == 'A'){
            WAcount++;
        }else if(str[0] == 'T' && str[1] == 'L' && str[2] == 'E'){
            TLEcount++;
        }else if(str[0] == 'R' && str[1] == 'E'){
            REcount++;
        }
        i++;
    }
    printf("AC x %d\n", ACcount);
    printf("WA x %d\n", WAcount);
    printf("TLE x %d\n", TLEcount);
    printf("RE x %d\n", REcount);

}


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

int main() {
	int y, m, d;
	while (cin >> y >> m >> d) {
		string ans;
		int c;
		if ((y > 1989) || (y == 1989 && (m > 1 || (m == 1 && d >= 8)))) { ans = "heisei"; c = y - 1988; }
		else if ((y > 1926) || (y == 1926 && (m > 12 || (m == 12 && d >= 25)))) { ans = "showa"; c = y - 1925; }
		else if ((y > 1912) || (y >= 1912 && (m > 7 || (m == 7 && d >= 30)))) { ans = "taisho"; c = y - 1911; }
		else if ((y > 1868) || (y >= 1868 && (m > 9 || (m == 9 && d >= 8)))) { ans = "meiji"; c = y - 1867; }
		else { puts("pre-meiji"); continue; }
		cout << ans << ' ' << c << ' ' << m << ' ' << d << endl;
	}
	return 0;
}



Measured memory_bytes: 3076
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

  // String nyuA=sc.nextLine();
  // String nyuB=sc.nextLine();
 
     String[] S=sc.nextLine().split(" ");

//int n=Integer.parseInt(nyuA);

int W=Integer.parseInt(S[0]);
int a=Integer.parseInt(S[1]);
int b=Integer.parseInt(S[2]);


//long H=Long.parseLong(t[0]);
//long W=Long.parseLong(t[1]);
//long C=Long.parseLong(t[2]);
if(Math.abs(a-b)>W){
System.out.println(Math.abs(a-b)-W);
}else{
System.out.println(0);
}


	}
}

Measured memory_bytes: 25172
#include <stdio.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, n) for(int i = 1; i <= n; ++i)

typedef long long ll;

int main(void) {
  ll n, m, i, j, k, q, s, t;
  scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
  ll a[n + 1], d[n + 1], now = 0;
  d[0] = 0;
  scanf("%lld", &a[0]);
  repi(i, n) {
    scanf("%lld", &a[i]);
    d[i] = a[i] - a[i - 1];
    if(d[i] > 0) now -= d[i] * s;
    else now -= d[i] * t;
  }
  rep(i, q) {
    ll l, r, x;
    scanf("%lld%lld%lld", &l, &r, &x);
    r++;
    if(d[l] > 0) now += d[l] * s;
    else now += d[l] * t;
    if(r != n + 1) {
      if(d[r] > 0) now += d[r] * s;
      else now += d[r] * t;
      d[r] -= x;
    }
    d[l] += x;
    if(d[l] > 0) now -= d[l] * s;
    else now -= d[l] * t;
    if(r != n + 1) {
      if(d[r] > 0) now -= d[r] * s;
      else now -= d[r] * t;
    }
    printf("%lld\n", now);
  }
  return 0;
}


Measured memory_bytes: 5872
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 105005
#define PI 	3.14159265358979323846

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    int n;
    cin >> n;
    static bool a[1000005];
    int i=1;
    while(1){
        if(a[n]){
            cout << i << endl;
            return 0;
        }else{
            a[n] = true;
        }
        if(n%2==0){
            n /= 2;
        }else{
            n *= 3;
            n += 1;
        }
        i++;
    }
}

/*
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cake[1050][3];//0,1,2
    REP(i,n)REP(j,3)cin >> cake[i][j];
    //nデータを8パターンで全探索
    static ll sum[8][3];
    REP(i,n){
        //+++:1
        
        //++-:2
        //+--:3
        //---:4
        //--+:5
        //-++:6
        //-+-:7
        //+-+:8
    }
   return 0;
}*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INT long long int
#define MOD (INT)(6e18)
using namespace std;
INT n, a[100010], b[100010], c[100010], bb[100010], cc[100010], ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i];
    for(int i = 0 ; i < n ; i++ ) cin>>b[i];
    for(int i = 0 ; i < n ; i++ ) cin>>c[i];
    sort(a, a+n);
    sort(b, b+n);
    sort(c, c+n);
    for(int i = 0 ; i < n ; i++ )
        cc[i] = (int)(lower_bound(b, b+n, c[i])-b);
    for(int i = 0 ; i < n ; i++ )
        bb[i] = (int)(lower_bound(a, a+n, b[i])-a);
    for(int i = 1 ; i < n ; i++ )
        bb[i] += bb[i-1];
    for(int i = 0 ; i < n ; i++ )
        ans += bb[cc[i]-1];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;

  bool colors[8];
  for (int i = 0; i < 8; i++) colors[i] = false;

  int free = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a <= 399) colors[0] = true;
    else if (a <= 799) colors[1] = true;
    else if (a <= 1199) colors[2] = true;
    else if (a <= 1599) colors[3] = true;
    else if (a <= 1999) colors[4] = true;
    else if (a <= 2399) colors[5] = true;
    else if (a <= 2799) colors[6] = true;
    else if (a <= 3199) colors[7] = true;
    else free++;
  }
  
  int pattern = 0;
  for (int i = 0; i < 8; i++) {
    if (colors[i]) pattern++;
  }

  int ans_min = max(1, pattern);
  int ans_max = pattern + free;
  cout << ans_min << " " << ans_max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int a,b,c,d;

int main(){
	cin>>a>>b>>c>>d;
	cout<<max(a*b,c*d)<<endl;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long x; cin >> x;
    long long curr = 100; int cnt = 0;
    while (curr < x) {
        curr += curr / 100; cnt++;
    }
    cout << cnt << "\n";
    return 0;
}

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

namespace AtCoder_Project_CSharp
{
    class Program
    {

        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());

            Console.WriteLine(r < 1200 ? "ABC" : r < 2800 ? "ARC" : "AGC");


        }
    }
}


Measured memory_bytes: 13140
//コピペ乙
//#7480900

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;


int main(){
  int N,count=0;
  string S;
  cin>>N>>S;

  for(int i=0;i<N;i++){
    if(S[i]=='(') count++;
    else{
      if(count>0) count--;
      else cout<<"(";
    } 
  }
  cout<<S;
  count=0;
  for(int i=N-1;i>=0;i--){
    if(S[i]==')') count++;
    else{
      if(count>0) count--;
      else cout<<")";
    } 
  }
  cout<<endl;
}

Measured memory_bytes: 256
n = int(input())
from copy import copy

L = ["a"]
if n == 1:
    print(L[0])
    exit()
    
for i in range(n-1):
    li = []
    for s in L:
        max1 = max(s)
        S = ""
        for j in range(ord(max1)-95):
            S = s + chr(97+j)
            #print(ord(max1)-95,chr(ord(max1)+j))
            li.append(S)
    L = copy(li)
    
print("\n".join(L))


Measured memory_bytes: 20984
#include <iostream>
#include <vector>

using namespace std;

struct data
{
	int id;
	int P;
	int Q;
	int R;
	int Calorie;
};

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<data> food(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> food[i].id >> food[i].P >> food[i].Q >> food[i].R;
			food[i].Calorie = 4 * food[i].P + 9 * food[i].Q + 4 * food[i].R;
		}
		int P, Q, R, Calorie;
		cin >> P >> Q >> R >> Calorie;
		bool isExist = false;
		for (int i = 0; i < n; ++i)
		{
			if (food[i].P <= P && food[i].Q <= Q && food[i].R <= R && food[i].Calorie <= Calorie)
			{
				isExist = true;
				cout << food[i].id << endl;
			}
		}
		if (!isExist)
		{
			cout << "NA" << endl;
		}
	}
}

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

Measured memory_bytes: 1212
int main(void)
{

    int N;
    scanf("%d", &N);
    char *str;
    str = (char *)malloc(sizeof(char) * N);
    scanf("%s", str);
    int L = strlen(str);
    printf("%d", ret_sl(str, L));
    return 0;
}

int ret_sl(const char txt[], int l)
{
    char *pat;
    pat = (char *)malloc(sizeof(char) * l);
    int pt = 0;
    int pp = 0;
    int count = 0;
    pat[pp] = txt[0];
    /*for(int i=0;i<N;i++){
        pat[pp] = txt[i];
    }*/
    while (txt[pt] != '\0' && pat[pp] != '\0')
    {
        if (txt[pt] == pat[pp])
        {
            pt++;
        }
        else
        {
            count += 1;
            pat[pp] = txt[pt];
        }
    }
  	if(txt[pt]=='\0'){
        return count + 1;
    }

    return count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    //#define int long long
    typedef long long ll;
    #define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
    #define forn(i, n) fore(i, 0, n)
    #define fori(i, l, r) fore(i, l, (r) + 1)
    #define sz(v) int((v).size())
    #define all(v) (v).begin(), (v).end()
    #define pb push_back
    #define mp make_pair
    #define ff first
    #define ss second
    using namespace std; 
     
    const double PI = atan(1)*4;

    int dx[8]={1,0,-1,0,1,-1,-1,1};
    int dy[8]={0,1,0,-1,1,1,-1,-1};
     
     
    bool isprime(int n)
    {
        for(int i=2;i*i<=n;i++)
            if(n%i==0)
                return false;
        return true;
    }

    const int mod = 998244353;
     
    bool comp(pair<int,int> a, pair<int,int> b)
    {
        return b.ff < a.ff ;
    }
     
    ll pw(ll b, ll e)
    {
        ll ans = 1;
        while(e)
        {
            if(e & 1)
                ans = (ans * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return ans;
    }

    ll fact[200002], inv[200002];
    
    ll C(ll n, ll k)
    {
        return ((((fact[n] * inv[k]) % mod) * inv[n-k]) % mod);
    }
     
    /*void bsearch(int max,int min)   //  for function 
    //void bsearch(int a,int n, int x)     // for array
    {
        int k=min;
     
        //  for array
     
    /*    for(int b=n/2; b>=1; b/=2)
        {
            while(k+b<n && arr[k+b]<=x) k+=b; 
        }
     
        if(arr[k]==x)
            cout<<"found at "<<k+1;
        else
            cout<<"not found";
    */
     
        //  for function 
     
    /*    for(int b=max; b>=1; b/=2)
        {
            while( !fn(b+k) ) k+=b;
        }
        cout<<k+1;
     
    }*/
     
    int vis[200005];
     
    int main()
    {
     
        int t=1;
        //cin>>t;
     
        while(t--)
        {
            int n,W;
            cin>>n>>W;

            int w[n],v[n];
            forn(i,n)
            {
                cin>>w[i]>>v[i];
            }

            ll dp[n+1][W+1];
            fori(i,0,n) dp[i][0]=0;
            fori(i,0,W) dp[0][i] =0;

            fori(i,1,n)
            {
                fori(j,1,W)
                {
                    if(w[i-1]<=j)
                    {
                        dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]] , dp[i-1][j]);
                    }
                    else
                    {
                        dp[i][j] = dp[i-1][j];
                    }
                }
            }

            cout<<dp[n][W];
        }
        return 0;
    }

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

template<typename T>
ostream& operator<<(ostream &os, vector<T> &v){
	string sep = " ";
	if(v.size()) os << v[0];
	for(int i=1; i<v.size(); i++) os << sep << v[i];
	return os;
}

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

#ifdef DBG
void debug_(){ cout << endl; }
template<typename T, typename... Args>
void debug_(T&& x, Args&&... xs){
	cout << x << " "; debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << fixed;
	int n; cin >> n;
	vector<int> a(n); cin >> a;
	map<int, int> cnt;
	ll sum = 0;
	for(int i=0; i<n; i++){
		cnt[a[i]]++;
		sum += a[i];
	}

	int q; cin >> q;
	for(int i=0; i<q; i++){
		int b, c; cin >> b >> c;
		if(cnt.count(b)==0) {
			cout << sum << endl;
			continue;
		}
		int m = cnt[b];
		sum += m*(c-b);
		cout << sum << endl;
		cnt.erase(b);
		cnt[c] += m;
	}
	return 0;
}


Measured memory_bytes: 6524
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10);
    const A = parseInt(args[1], 10);
    const B = parseInt(args[2], 10);
  var max,min
  
	if(A+B-N>0){
      min = A+B-N
    }else{
      min = 0
    }
  if(A>B){
    max = B
  }else{
    max = A
  }
  
  console.log(max + " " + min)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>

using namespace std;

bool is_prime(int x) {
  if (x <= 1) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;
  for (int d = 3; d * d <= x; d += 2) {
    if (x % d == 0) return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int x;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (is_prime(x)) ++ans;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = [0] * Q
C = [0] * Q
for i in range(Q):
    B[i], C[i] = map(int, input().split())

cnt = [0] * (10**5 + 1)
total = 0
for a in A:
    cnt[a] += 1
    total += a

for i in range(Q):
    total -= B[i] * cnt[B[i]]
    total += C[i] * cnt[B[i]]
    cnt[C[i]] += cnt[B[i]]
    cnt[B[i]] = 0
    print(total)


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

#define LL long long
#define Dl double
#define Pb push_back
#define Po pop_back
#define Mp make_pair
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

typedef vector<LL> Vl;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

LL mod = 1e9 + 7;
LL fac[200010], finv[200010], inv[200010];


void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(LL i = 2; i <= 200010; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

LL ncr(LL n, LL k)
{
    if(n < k)
        return 0;
    if(n < 0 || k < 0)
        return 0;

    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

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

    COMinit();

    LL H, W, A, B;
    cin >> H >> W >> A >> B;

    LL h = H - A, w = W - B;

    LL ans = 0;

    for(LL i = 0; i < h; i++){
        ans = (ans + (ncr(i + B - 1, B - 1) * ncr(H - i + w - 2, w - 1)) % mod) % mod;
    }

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



Measured memory_bytes: 4992
#include <algorithm>
#include <iostream>
#include "vector"
#include "stack"
#include "utility"
#include "bits/stdc++.h"

using namespace std;
//vector<long long> factors;
#define ll long long

#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x0f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

ll mod(ll a, ll m) { return (a + (abs(a) / m) * m + m) % m; }

long double cnt_dst(pll p1, pll p2) {
    return sqrt(pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2));
}

vector<pll > xy;

long double cnt_len(const vector<ll> &perm) {
    long double res = 0;
    for (int i = 0; i < perm.size() - 1; ++i) {
        res += cnt_dst(xy[perm[i]], xy[perm[i + 1]]);
    }
    return res;
}

int main() {
    IOS

    ll n;
    cin >> n;
    xy.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> xy[i].first >> xy[i].second;
    }

    ll div = n * (n - 1) / 2;
    vector<ll> per(n);
    for (int i = 0; i < n; ++i) {
        per[i] = i;
    }
    long double sm = 0;
    vector<ll> cp = per;
    ll cnt = 0;
    do {
        ++cnt;
        sm += cnt_len(per);
        next_permutation(all(per));
    } while (per != cp);
    cout << fixed;
    cout << setprecision(10) << sm / cnt;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define ll long long
int main(){
  ll N,i;
  cin >> N;
  ll V[N],C[N];
  for(i=0;i<N;i++){
    cin >> V[i];
  }
  for(i=0;i<N;i++){
    cin >> C[i];
  }
  ll ans=0;
  for(i=0;i<N;i++){
    ans=max(ans,ans+V[i]-C[i]);
  }
  cout << ans;
  return 0;
}

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


int main()
{
	int n; cin >> n;
	int d[55];
	for (int i = 0; i < n; ++i)
		cin >> d[i];
	int sum = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			sum += d[i]*d[j];
	cout << sum << endl;
}



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

vector<long long int> a,b,c,mix;

int X,Y,Z,K;
int main () {
    cin >> X >> Y >> Z >> K;
    for(int i=0; i<X; i++) {
        long long int x;
        cin >> x;
        a.push_back(x);
    }
    for(int i=0; i<Y; i++) {
        long long int x;
        cin >> x;
        b.push_back(x);
    }
    for(int i=0; i<Z; i++) {
        long long int x;
        cin >> x;
        c.push_back(x);
    }

    sort(a.rbegin(),a.rend());
    sort(b.rbegin(),b.rend());
    sort(c.rbegin(),c.rend());
    for(int i=0;i<X; i++) {
        for(int j=0; j<Y; j++) {
            if( (i+1) * (j+1) > K ) break;
            for(int k=0; k<Z; k++) {
                if( (i+1) * ((j+1) * (k+1) > K) ) break;
                mix.push_back(a[i] + b[j] + c[k]);
            }
        }
    }
    sort(mix.rbegin(),mix.rend());
    for(int i=0; i<K; i++) cout << mix[i] << endl;

    return 0;
}

Measured memory_bytes: 67948
N = int(input())
Lin = input().split(" ")

Lls = []

for i in range(0,N):
    Lls.append(int(Lin[i]))

Lls.sort(reverse = True)

maxSide = Lls[0]
otherSide = 0
for i in range(1,N):
    otherSide = otherSide + Lls[i]

if maxSide < otherSide:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int M, D; cin >> M >> D;
  int ans = 0;
  for (int m = 1; m <= M; ++m) {
    for (int d = 1; d <= D; ++d) {
      if (d%10 < 2 || d/10 < 2) continue;

      if (m == (d % 10) * (d / 10)) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll sum(ll a,ll b){
    ll ret=0;
    while(a>0){
        ret+=a%b;
        a/=b;
    }
    return ret;
}

int main(){
    ll n,x,ans=longinf;
    cin>>n>>x;
    if(n==x){
        cout<<x+1<<endl;
        return 0;
    }
    for(ll i=2;i*i<=n;i++){
        if(sum(n,i)==x){
            cout<<i<<endl;
            return 0;
        }
    }
    for(ll i=1;i*i<n;i++){
        if(i>x)break;
        if((n-x+i)%i==0){
            ll y=(n-x+i)/i;
            if(y>x-i){
                ans=min(ans,y);
            }
        }
    }
    cout<<(ans==longinf?-1:ans)<<endl;
    return 0;
}


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

typedef long long ll;

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

    int m1,d1,m2,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    if(m1==m2) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
a[5],t[4];main(i){for(;i=scanf("%d",a)&&*a;){t[1]=t[2]=t[3]=0;for(t[*a]++;i<5;t[a[i++]]++)scanf("%d",a+i);if(!!t[1]^!!t[2]^!!t[3])puts("3\n3\n3\n3\n3");else for(i=0;i<5;puts(t[a[i++]%3+1]?"1":"2"));}exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll N,M;
string S="";
ll A[13],B[13];

int main(){
    ll N;
    cin >> N;
    cout << (N*800-N/15*200) << endl;
}

Measured memory_bytes: 256
def comb(n):
    return n * (n - 1) // 2

N=int(input())
S=[]
for i in range(N):
    S.append(input())

w_list = []

for ss in S:
    s = sorted([i for i in ss])
    w_list.append("".join(s))
    
w_list.sort()

ans = 0
anagram = 1
temp = w_list[0]

for i in range(1, N):
    if temp == w_list[i]:
        anagram += 1
    else:
        ans += comb(anagram)
        anagram = 1
        temp = w_list[i]

ans += comb(anagram)
    
print(ans)

Measured memory_bytes: 69208
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=998244353;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2LL*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, k;

int main(void)
{
	cin>>n>>k;
	cout<<k*pexp(k-1,n-1);
	return 0;
}
// 제출하기 전에 생각햇나요?
// it may be easier/harder than you think
// ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
N = int(input())

g = [[] for _ in range(N+1)]

for i in range(N-1):
    a, b, c = map(int, input().split())
    g[a].append([b, c])
    g[b].append([a, c])
    
Q, K = map(int, input().split())

cost = [-1] * (N+1)
cost[K] = 0
temp = [K]
while temp:
    p = temp.pop()
    for q in g[p]:
        if cost[q[0]] == -1:
            cost[q[0]] = cost[p] + q[1]
            temp.append(q[0])

for i in range(Q):
    x, y = map(int, input().split())
    print(cost[x] + cost[y])


Measured memory_bytes: 49740
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int n, r;
  while(1) {
    cin >> n >> r;
    if(n==0 && r==0) break;
    int num[n+1];
    FOR(i,0,n+1) num[i] = i;
    while(r--) {
      int p, c;
      scanf("%d %d\n", &p, &c);
      int tmp[c+p-1];
      FOR(i,0,c) {
        tmp[i] = num[n-(p-1)-i];
      }
      FOR(i,c,c+p-1) {
        tmp[i] = num[n-(i-c)];
      }
      FOR(i,0,c+p-1) num[n-i] = tmp[i];
    }
    printf("%d\n", num[n]);
  }
  return 0;
}

Measured memory_bytes: 3148
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define ld long double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

char a[1010][1010];
ll dp[1010][1010];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int h, w;
	cin >> h >> w;
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			cin >> a[i][j];
		}
	}
	dp[1][1] = 1;
	for(int i = 1; i <= h; i++) {
		for(int j = 1; j <= w; j++) {
			if(i == 1 && j == 1) continue;
			if(a[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
		}
	}
	cout << dp[h][w];
}

Measured memory_bytes: 9216
import sys
from io import StringIO
import unittest

def resolve():
    N, M = [int(x) for x in input().rstrip().split()]

    digits = [-1] * N

    for _ in range(M):
        S, C = [int(x) for x in input().rstrip().split()]
        index = S -1

        if digits[index] != -1 and digits[index] != C:
            print("-1")
            return

        digits[index] = C

    if N >= 2:
        if(digits[0] == 0):
            print("-1")
            return

        if(digits[0] == -1):
            digits[0] = 1

    for d in digits:
        if d == -1:
            d = 0
        print(d, end="")

    print()

resolve()

Measured memory_bytes: 51308