akhauriyash/Code-Regression huggingface dataset:
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int wt=in.nextInt();
		int [] w=new int [n];
		int [] v=new int [n];
		for(int i=0;i<n;i++)
		{
			w[i]=in.nextInt();
			v[i]=in.nextInt();
		}
		long [][] ans =new long [n][wt+1];
		for(int i=w[0];i<=wt;i++)
		{
			ans[0][i]=v[0];
		}
		for(int i=1;i<n;i++)
		{
			for(int j=0;j<=wt;j++)
			{
				if(j>=w[i])
				{
					ans[i][j]=Math.max(ans[i-1][j],(ans[i-1][j-w[i]]+v[i]));
				}
				else
				{
					ans[i][j]=ans[i-1][j];
				}
			}
		}
		long max=0;
		for(int i=0;i<=wt;i++)
		{
			if(ans[n-1][i]>max)
			{
				max=ans[n-1][i];
			}
		}
		System.out.println(max);
	}
}

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

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

	int cnt=0;
	for (int i = 0; i < n; ++i){
		int a;
		cin>>a;
		if(a%2==1)
			cnt++;
	}

	if(cnt%2==1)
		cout<<"NO"<<endl;
	else
		cout<<"YES"<<endl;

}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m = MOD){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
inline int modinv(int a){return powerexp(a,MOD-2,MOD);}
inline int lcm(int a,int b){int g=__gcd(a,b);return a/g*b;}

//-------------------< start here >-------------------------// 

const int N = 2e5+11;
int fact[N], invfact[N];
void pre(){
  fact[0] = 1;
  invfact[0] = 1;
  for(int i = 1 ; i <= N; i++){
	   fact[i] = i * fact[i-1];
	   fact[i] %= MOD;
	   invfact[i] = modinv(fact[i]); 
	 }	
}

int nCr(int n,int r){
	if (r > n)
	    return 0;
	int ret = fact[n];
	ret *= invfact[n-r];
	ret %= MOD;
	ret *= invfact[r];
	ret %= MOD;
	return ret;
}

map<int,int> factorise(int n){
   map<int,int> m;
   for(int i = 2; i * i <= n; i++){
	    if ( n% i == 0){
	    while (n % i == 0){
		   n /= i;
		   m[i]++;	
		} 
	  }	
   }
   if (n > 1) m[n]++;
  return m;
}

void solve(){
	pre();
	//map<int, int> m  = factorise(12);
	//for(auto it : m)cout << it.f << " " << it.s << endl;
    int n, m;
    cin >> n >> m;
    map<int,int> v = factorise(m);
    int ret = 1;
    for(auto it : v){
	   ret *= nCr( it.s + n -1 , n - 1);	
	   ret %= MOD;
	}
	cout << ret << endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
   #endif
}


Measured memory_bytes: 3456
import fractions

def ceil(n, m):
    if n % m == 0:
        ans = n // m
    else:
        ans = (n + m) // m
    return ans

q = [0] * 3
nmul = [0] * 3

lower, upper, q[0], q[1] = [int(x) for x in input().split()]
q[2] = (q[0] * q[1]) // fractions.gcd(q[0], q[1])

for i in range(3):
    left = lower if (lower % q[i] == 0) else lower + q[i] - (lower % q[i])
    nmul[i] = ceil( upper - left + 1, q[i])

ans = upper - lower + 1 - nmul[0] - nmul[1] + nmul[2]

print(ans)

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int n;cin>>n;
    int u=n/100;     
    int l=n%100;
    string s;
    if(1<=u&&u<=12&&1<=l&&l<=12) s= "AMBIGUOUS";
    else if(1<=u&&u<=12) s="MMYY";
    else if(1<=l&&l<=12) s="YYMM";
    else s = "NA";
    cout<<s<<endl;
    return 0;
}


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

typedef long long LL;

using namespace std;

bool solve(LL interval, LL x){
	for (int i = 0; i <= 200; i++){
		LL a = i, b = i - interval;
		if (pow(a, 5) - pow(b, 5) == x){
			cout << a << " " << b << endl;
			return 1;
		}
		if (pow(a, 5) - pow(b, 5) > x && b >= 0) break;
	}
	return 0;
}

int main(){
	int x;
	cin >> x;
	for (int i = 1; i <= floor(sqrt(x)); i++){
		if (x % i == 0){
			if (solve(i, x) || solve(x / i, x)) break;
		}
	}
	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,M;
  cin>>N>>M;
  vector<int>A(M),B(M);
  for(int i=0;i<M;i++)cin>>A[i]>>B[i],A[i]--,B[i]--;
  vector<vector<int>>G(N);
  for(int i=0;i<M;i++)G[B[i]].push_back(A[i]),G[A[i]].push_back(B[i]);
  vector<int>ans(N,-1);
  queue<int>q;
  q.push(0);
  vector<bool>b(N,false);
  while(q.size()){
    int now=q.front();
    q.pop();
    for(auto it:G[now]){
      if(!b[it]){
        ans[it]=now;
        q.push(it);
        b[it]=true;
      }
    }
  }
  bool ok=true;
  for(int i=1;i<N;i++)if(ans[i]==-1)ok=false;
  if(!ok)cout<<"No"<<endl;
  else{
    cout<<"Yes"<<endl;
    for(int i=1;i<N;i++)cout<<ans[i]+1<<endl;
  }
  return 0;
}


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

double dist(vector<double> &x, vector<double> &y, pair<double, double> vertex)
{
    double ret = 0.;
    double xx = vertex.first;
    double yy = vertex.second;
    for (int i = 0; i < x.size(); i++)
    {
        ret = max(ret, (x[i] - xx) * (x[i] - xx) + (y[i] - yy) * (y[i] - yy));
    }
    return ret;
}

double f(double A, double B, double C, double a, double b, double c)
{
    double numerator = 0.;
    a *= a;
    b *= b;
    c *= c;
    numerator += a * (b + c - a) * A;
    numerator += b * (c + a - b) * B;
    numerator += c * (a + b - c) * C;

    double denominator = 0.0;
    denominator += a * (b + c - a);
    denominator += b * (c + a - b);
    denominator += c * (a + b - c);
    if (denominator <= 0)
    {
        return 2000.;
    }
    return numerator / denominator;
}

pair<double, double> center(set<pair<double, double>> vertex)
{
    if (vertex.size() == 1)
    {
        return *vertex.begin();
    }
    if (vertex.size() == 2)
    {
        double x = 0.;
        double y = 0.;
        for (pair<double, double> v : vertex)
        {
            x += v.first / 2.;
            y += v.second / 2.;
        }
        return make_pair(x, y);
    }
    if (vertex.size() == 3)
    {
        // https://ja.wikipedia.org/wiki/%E5%A4%96%E6%8E%A5%E5%86%86#%E5%A4%96%E5%BF%83%E3%81%AE%E4%BD%8D%E7%BD%AE
        vector<double> xs;
        vector<double> ys;
        for (pair<double, double> v : vertex)
        {
            xs.push_back(v.first);
            ys.push_back(v.second);
        }
        double a = sqrt(pow(xs[1] - xs[2], 2) + pow(ys[1] - ys[2], 2));
        double b = sqrt(pow(xs[2] - xs[0], 2) + pow(ys[2] - ys[0], 2));
        double c = sqrt(pow(xs[0] - xs[1], 2) + pow(ys[0] - ys[1], 2));
        double Ax = xs[0];
        double Bx = xs[1];
        double Cx = xs[2];
        double Ay = ys[0];
        double By = ys[1];
        double Cy = ys[2];
        return make_pair(f(Ax, Bx, Cx, a, b, c), f(Ay, By, Cy, a, b, c));
    }
    else
    {
        return make_pair(0., 0.);
    }
}

int main()
{
    int N;
    cin >> N;
    vector<double> x(N);
    vector<double> y(N);

    for (int i = 0; i < N; i++)
    {
        cin >> x[i] >> y[i];
    }

    double ans = 1000. * 1000.;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            for (int k = 0; k < N; k++)
            {
                set<pair<double, double>> vertex;
                vertex.insert(make_pair(x[i], y[i]));
                vertex.insert(make_pair(x[j], y[j]));
                vertex.insert(make_pair(x[k], y[k]));
                pair<double, double> c = center(vertex);
                ans = min(ans, dist(x, y, c));
            }
        }
    }
    cout << fixed << setprecision(8) << sqrt(ans) << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
	string s,t;
	int i;
	cin>>s>>t;
	int an=s.length(),bn=t.length();
	int a[an],b[bn];
	for(i=0;i<an;i++)a[i]=s[i];
	for(i=0;i<bn;i++)b[i]=t[i];
	sort(a,a+an);
	sort(b,b+bn);
	s=t="";
	for(i=0;i<an;i++)s+=a[i];
	for(i=bn-1;i>=0;i--)t+=b[i];
	if(s<t)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	
	
	
//////////////////////////////////////////////////////
	return 0;
}


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

int main(){
	int l, n, in, s, imin, fmin;
	cin >> n >> l;
	vector<int> f(n);
	for(int i=0; i<n; i++){
		f[i] = l + i+1 - 1;
	}
	s = 0;
	for(int i=0; i<n; i++){
		s += f[i];
	}
	fmin = 10000;
	for(int i=0; i<n; i++){
		if(fmin > abs(f[i])){
			fmin = abs(f[i]);
			imin = i;
		}
	}
	cout << s-f[imin] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i = 0; i< (n); ++i)
const long long INF = 1LL<<58;

// aを常に小さい値にする
template<class T> void chmin(T &a, T b){ if(a>b) a = b; }
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

/*
 * */

bool check(char c1, char c2){
    return (c1 == 'A' && c2 == 'C');
}

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

    string S;
    cin >> S;

    // 最初の文字からN文字目までのACの数を累積和として求めておく
    int sum[S.size()];
    rep(i, S.size()){
        sum[i] = 0; // 初期化
    }
    rep(i, S.size()) {
        if(i == 0) continue;
        if(S[i-1] == 'A' && S[i] == 'C'){
            sum[i] = sum[i-1] + 1;
        }else{
            sum[i] = sum[i-1];
        }
    }

    rep(i,Q) {
        unsigned l, r;
        cin >> l >> r;
        int res = sum[r-1] - sum[l-1];
        cout << res << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  ll A[N]; rep(i,N) cin >> A[i];
  map<ll, ll> sum; rep(i,N) sum[i-A[i]]++;

  ll result = 0;
  rep(i,N) {
    sum[i-A[i]]--;
    result += sum[i+A[i]];
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 27880
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B > C + D)cout << "Left";
	else if (A + B < C + D)cout << "Right";
	else cout << "Balanced";
}


Measured memory_bytes: 256
N = int(input())
nums = list(map(int, input().split(" ")))

all_sum = sum(nums)
sums = [None] * N

min_diff_value = float('inf')
min_diff_index = -1


for i in range(N-1):
    if i==0:
        sums[i] = nums[i]
    else:
        sums[i] = sums[i-1] + nums[i]

    lhs_value = sums[i]
    rhs_value = all_sum - lhs_value
    diff_value = abs(lhs_value - rhs_value)

    if diff_value < min_diff_value:
        min_diff_value = diff_value

print(min_diff_value)        







Measured memory_bytes: 30504
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var (n, k) = (nk[0], nk[1]);
        var seqA = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var up = new bool[seqA.Length];
        for (int i = k; i < seqA.Length; ++i)
        {
            int j = i - k;
            up[i] = seqA[j] < seqA[i];
        }

        Console.WriteLine(string.Join(Environment.NewLine, up.Skip(k).Select(x => x ? "Yes" : "No")));
    }
}


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

int main(){
  int A;
  cin >> A;
  vector<int>b(A+1);
  vector<int>c(A+1);
  vector<int>d(A+1);
  int ans=0;
  
  for(int i=0;i<A;i++){
    cin >> b.at(i);
  }
  for(int i=0;i<A;i++){
    cin >> c.at(i);
  }
  for(int i=0;i<A-1;i++){
    cin >> d.at(i);
  }
  for(int i=0;i<A;i++){
    ans+=c.at(b.at(i)-1);
    if(b.at(i)==b.at(i+1)-1){
      ans+=d.at(b.at(i)-1);
    }
  }
  cout << ans << endl;
  
}

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

public class MainClarss
{
	public const long Giri = 1000000007;
	
	public static void Main(string[] args)
	{
		//string[] o = Input();
		int n = int.Parse(Console.ReadLine());
		List<Ary> ars = new List<Ary>(n);
		
		for( int i = 0; i < n; i++)
		{
			int k = int.Parse(Console.ReadLine());
			ars.Add(new Ary(){ID=i+1,A=k});
		
		}
		ars.Sort((a, b) => b.A-a.A);
		
		for(int i = 0; i < n;i++)
		{
			for(int j = 0; j < n; j++)
			{
				if(ars[j].ID!=i+1)
				{
					Console.WriteLine(ars[j].A);
					break;
				}
			}
			
		}
	}

	class Ary
	{
		public int ID{get;set;}
		public int A{get;set;}
	}
	public static long GCD(long a, long b)
	{
		if(b == 1)
			return a;
		long p = b / a;
		return GCD(a, b - a*p);
	}
	
	public static string[] Input()
	{
		return Console.ReadLine().Split(' ');
	}

	
	public static int Clamp(int val, int max, int min = 0)
	{
		return Math.Min(max, Math.Max(min, val));
	}

}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  int a,b;
  cin>>a>>b;
  int ans=0;
  REP(i,2){
    if(a>b){
      ans += a;
      a--;
    }else{
      ans += b;
      b--;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll x;
  cin>>x;
  if(x==7||x==5||x==3){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }

  return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;
template<class T> using v = vector<T>;
template<class T, class U> using p = pair<T, U>;

#define REP(i, n) for(ll i = 0; i < n; ++i)
#define REP1(i, n) for(ll i = 1; i <= n; ++i)
#define REP2(i, B, E) for(ll i = B; i <= E; ++i)

template<class T> T read() { T x{}; cin >> x; return x; }
template<class T> v<T> read(int N){ v<T> x(N); REP(i, N) cin >> x[i]; return x; }

template<class T>
void write(const T &x){ cout << x << endl; }
void write(double x){ printf("%.15f\n", x); }

template<class T> T& chmin(T &obj, T val){ return obj = min(obj, val); }
template<class T> T& chmax(T &obj, T val){ return obj = max(obj, val); }

// 二分探索 : [low, high) の範囲で述語 pred がtrue を返す最大の値を返す
template<class Pred>
ll bsearch(ll low, ll high, Pred pred){
    while(low + 1 < high){
        const ll mid = low + (high - low) / 2;
        if(pred(mid)){ low = mid; }
        else{ high = mid; }
    }
    return low;
}


const ll MOD = (ll)1e9 + 7;


int main() {
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
    
    
    
}



Measured memory_bytes: 256
//#pragma  GCC optimize("Ofast")

//#ifdef  DEBUG
//#define _GLIBCXX_DEBUG
//#endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;
//using namesparsace __gnu_pbds;

void solve();

int main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
    return 0;
}

#define ld double
#define int long long

const int maxN = 3e3 + 10, maxK = 1e5 + 10, inf = 1e15 + 10, mod = 1e9 + 7, base = 223;

int n, dp[maxN][maxN], pref[maxN], suf[maxN];
string s;

void solve() {
    cin >> n >> s;
    dp[1][1] = 1;
    pref[1] = 1;
    pref[2] = 1;
    suf[1] = 1;
    suf[0] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            if (s[i - 2] == '>') {
                dp[i][j] = suf[j];
            } else {
                dp[i][j] = pref[j - 1];
            }
        }
        for (int j = 1; j <= i; j++) {
            pref[j] = (pref[j - 1] + dp[i][j]) % mod;
        }
        for (int j = i; j >= 1; j--) {
            suf[j] = (suf[j + 1] + dp[i][j]) % mod;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = (ans + dp[n][i]) % mod;
    }
    cout << ans;
}



Measured memory_bytes: 69248
package main

import (
	"fmt"
	"strings"
)

func main() {
	var Sa, Sb, Sc string
	fmt.Scan(&Sa, &Sb, &Sc)
	cur := "a"

	for {
		c := cur[0]
		if c == 'a' {
			cur = Sa
			if len(cur) == 0 {
				fmt.Println(strings.ToUpper(string(c)))
				return
			}
			Sa = Sa[1:]
		} else if c == 'b' {
			cur = Sb
			if len(cur) == 0 {
				fmt.Println(strings.ToUpper(string(c)))
				return
			}
			Sb = Sb[1:]

		} else if c == 'c' {
			cur = Sc
			if len(cur) == 0 {
				fmt.Println(strings.ToUpper(string(c)))
				return
			}
			Sc = Sc[1:]

		}

	}

}



Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int x[100001], y[100000];

int G[301][301];
bool checked[301][301];

signed main() {
	for (int i = 0; i < 301; i++) {
		for (int j = 0; j < 301; j++) {
			if(i!=j) G[i][j] = G[j][i] = LL_HALFMAX;
			else G[i][j] = G[j][i] = 0;
		}
	}
	
	int N;
	cin >> N;

	int sum = 0;
	int minus = 0;

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) {
			int inp;
			cin >> inp;
			G[i][j] = G[j][i] = inp;
			if (i > j)sum += inp;
		}
	}

	//WFをする
	bool flag = true;
	for (int k = 1; k <= N; k++) {
		for (int i = 1; i <= N; i++) {
			for (int j = 1; j <= N; j++) {
				if (i == k || j == k) continue;
				if (G[i][j] > G[i][k] + G[k][j]) {
					flag = false;
					G[i][j] = G[j][i] = G[i][k] + G[k][j];
				}

				if (i > j)continue;
				if (G[i][j] == G[i][k] + G[k][j] && !checked[i][j] && !checked[j][i]) {
					checked[i][j] = checked[j][i] = true;
					minus -= G[i][j];
				}
			}
		}
	}
	if (flag) cout << sum + minus << "\n";
	else cout << "-1\n";


	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h> 

int main()
{
    long a, b, tmp;
    long r,x;
    scanf("%ld%ld", &a, &b);

    if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
  x = a*b;
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  /* 最小公倍数を出力 */
  printf("%ld\n", x/b);
 
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	set<int> s;
	for(int i=0;i<3;++i){
		int x;
		cin>>x;
		s.insert(x);
	}
	cout<<int(s.size())<<'\n';
}




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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N;
	ll ans, a = 1LL, b = 1LL, n;
	
	cin >> N;
	
	ll T[N], A[N];
	
	for(int i=0; i<N; i++)
		cin >> T[i] >> A[i];
	
	for(int i=0; i<N-1; i++){
		if(T[i+1] < T[i] || A[i+1] < A[i]){
			n = max((T[i] + T[i+1] -1) / T[i+1], (A[i] + A[i+1] - 1) / A[i+1]);
			T[i+1] *= n;
			A[i+1] *= n;
		}
	}
	
	cout << T[N-1] + A[N-1];
	
	return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for i in range(n)]
count=0
for i in range(n):
  s=c
  for j in range(m):
    s+=a[i][j]*b[j]
  if s>0:
    count+=1
      
print(count)

Measured memory_bytes: 3060
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] sides = new int[3];
		for (int i = 0; i < n; i++) {
			sides[0] = scanner.nextInt();
			sides[1] = scanner.nextInt();
			sides[2] = scanner.nextInt();
			Arrays.sort(sides);
			System.out.println(
				sides[0] * sides[0] + sides[1] * sides[1] == sides[2] * sides[2] ?
				"YES" : "NO"
				);
		}
	}
}

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

using namespace std;

#define LL long long
#define pii pair<int,int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",&x)
#define rep(i,a,b) for(int i = a ; i <= b ; i++)
#define per(i,a,b) for(int i = b ; i >= a ; i--)
#define mem(a) memset(a,0,sizeof(a))
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define fast_io ios::sync_with_stdio(false)

const LL INF = 1e12;
const int mod = 1e4 + 7;
const int maxn = 2e5 + 7;

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
    int k;
    while(~sd(k)) {
        pd(a[k-1]);
    }
    return 0;
}


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

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

        while (true) {
            String[] S = sc.next().split("");
            List<String> cards = new ArrayList<>(Arrays.asList(S));

            if ("-".equals(cards.get(0))) break;

            int m = Integer.parseInt(sc.next());
            for (int i = 0; i < m; i++) {
                int s = Integer.parseInt(sc.next());

                for (int j = 0; j < s; j++) {
                    String tmp = cards.get(0);
                    cards.remove(0);
                    cards.add(tmp);
                }
            }
            cards.forEach(System.out::print);
            System.out.println();
        }
    }
}

Measured memory_bytes: 31632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)

ll N, M, K, S, p, q;
ll dmin[MAX_N];
vector<ll> c;
vector<vector<P> > g;
bool danger[MAX_N], zomb[MAX_N];

void bfs(){
    ll d[MAX_N];
    fill(d,d+N,IINF);
    for(auto s : c){
        zomb[s] = true;
        d[s] = 0;
        queue<P> que;
        que.push(P(s,0));
        while(!que.empty()){
            P pi = que.front();
            que.pop();
            ll u=pi.first, dt=pi.second;
            if(d[u]<dt)continue;
            if(dt>S)continue;
            for(auto qi : g[u]){
                ll v = qi.first;
                if(d[v]>dt+1){
                    que.push(P(v,dt+1));
                    d[v] = dt+1;
                }
            }
        }
    }
    REP(i,N){
        if(d[i]<=S) danger[i] = true;
    }
}

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(dmin, dmin + N, LLINF);
    dmin[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (dmin[v] < p.first) continue;
        for (auto &e : g[v]) {
            if (dmin[e.first] > dmin[v] + e.second) {
                dmin[e.first] = dmin[v] + e.second;
                que.push(P(dmin[e.first], e.first));
            }
        }
    }
}

int main() {
    cin >> N >> M >> K >> S >> p >> q;
    c.resize(K);
    g.resize(N);
    REP(i,K) {
        cin >> c[i];
        c[i]--;
    }
    REP(i,M){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(make_pair(b,p));
        g[b].push_back(make_pair(a,p));
    }

    // bfsで危険な町を判定
    bfs();

    // ゾンビの町への辺をINF, 危険な町への辺のコストをQとする
    REP(i,N){
        for(auto &e : g[i]){
            if(zomb[e.first]){
                e.second = LLINF/4;
            }
            else if(danger[e.first]){
                e.second = q;
            }
            if(e.first == N-1)e.second = 0;
        }
    }
    // dijkstraで最短経路を求める
    dijkstra(0);
    cout << dmin[N-1] << endl;

    return 0;
}


Measured memory_bytes: 17508
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
ll arr[500005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x;
    while(cin>>x)
    {
        ll mod=x%100;
        ll baki=x/100;
        while(mod>=5)
        {
            baki--;
            mod-=5;
        }
        while(mod>=4)
        {
            mod-=4;
            baki--;
        }
        while(mod>=3)
        {
            baki--;
            mod-=3;
        }
        while(mod>=2)
        {
            baki--;
            mod-=2;
        }
        while(mod>=1)
        {
            baki--;
            mod-=1;
        }
        if(mod==0 && baki>=0) cout<<1<<endl;
        else cout<<0<<endl;


    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <utility>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef pair<ll, double> PD;
//ll mod = 1000000007;
ll mod = 998244353;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n), b(n);
	ll sum = 0, goal = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		goal += a[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		sum += b[i];
	}
	priority_queue<P> pq;
	ll cnt = 0;
	for (int i = 0; i < n; i++) pq.push(P(b[i], i));
	while (sum > goal && !pq.empty()) {
		P p = pq.top();
		pq.pop();
		ll ps = p.second;
		sum -= b[ps];
		ll dis = b[(ps + 1) % n] + b[(ps + n - 1) % n];
		ll mov = (b[ps] - a[ps]) / dis;
		if (mov == 0 && b[ps] != a[ps]) {
			cout << -1 << endl;
			return 0;
		}
		b[ps] -= mov * dis;
		cnt += mov;
		sum += b[ps];
		if (mov != 0) pq.push(P(b[ps], ps));
	}
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 9328
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))

ar = a - range(1, len(a) + 1)
bm = np.median(ar)
b1, b2 = np.floor(bm), np.ceil(bm)
result1 = int(min(np.abs(ar - b1).sum(), np.abs(ar - b2).sum()))

bm = np.mean(ar)
b1, b2 = np.floor(bm), np.ceil(bm)
result2 = int(min(np.abs(ar - b1).sum(), np.abs(ar - b2).sum()))
print(min(result1, result2))


Measured memory_bytes: 34212
#include <stdio.h>

int main() {
  int n, q, i;
  scanf("%d", &n);

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

  scanf("%d", &q);
  int ans = 0;

  for (i = 0; i < q; i++) {
    int x;
    scanf("%d", &x);
    // x が 数列 s に含まれているか判定する
    // 区間 [low, high] が x が存在するかもしれない範囲
    int low = 0, high = n-1;
    while (low <= high) {
      // mid = (low + high) / 2 より OverFlow しにくい
      int mid = low + (high-low) / 2;
      // 値が見つかったとき
      if ( s[mid] == x ) {
        ans++;
        break;
      }
      // mid のほうが x より大きい
      else if (s[mid] > x) {
        high = mid-1;
      }
      // mid のほうが x より小さい
      else {
        low = mid+1;
      }
    }
  }

  printf("%d\n", ans);

  return 0;
}


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

const int MOD = 1e9 + 7;







int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M; cin >> N >> M;
  vector<LL> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];
  sort(A.begin(), A.end());
  vector<pair<LL, LL>> L;
  for (int i = 0; i < M; ++i) {
    LL B, C;
    cin >> B >> C;
    L.emplace_back(C, B);
  }
  sort(L.begin(), L.end());
  for (int i = 0; i < N; ++i) {
    while (L.size() and L.back().second == 0) L.pop_back();
    A[i] = L.empty() ? A[i] : max(L.back().first, A[i]);
    if (L.size()) --L.back().second;
  }
  cout << accumulate(A.begin(), A.end(), 0ll) << '\n';
}


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

using namespace std; 

string s;
string ans_ops;

int dfs(int i, int sum, string ops){
  if (i==s.size()){
    if (sum == 7) {
      ans_ops = ops;
    }
  } else {
    dfs(i+1,sum+(s.at(i)-'0'),ops+"+");
    dfs(i+1,sum-(s.at(i)-'0'),ops+"-");
  }
}

int main() {
  cin >> s;
  string ops = "";
  dfs(1,s.at(0)-'0',ops);
  for(int i=0; i<s.size(); i++){
    cout << s.at(i);
    if (i != s.size()-1) cout << ans_ops.at(i);
  }
  
  cout << "=7" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define n 100000
using namespace std;
int main(){
    int h[n],w[n];
    int N;
    for(int i=0;i<n;i++){
        cin >> h[i] >> w[i];
        if(h[i]==0 && w[i]==0){
            N=i;
            break;
        }
    }
    for (int k=0;k<N;k++){
        for(int i=0;i<h[k];i++){
            for(int j=0;j<w[k];j++){
                if(i==0 || j==0 || i==h[k]-1 || j==w[k]-1) cout << "#";
                else cout <<".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
    
}


Measured memory_bytes: 3104
S = input()


def main():
    judge = True

    for i in range(len(S)):
        # print("{} {}".format(S[i], S[-(i+1)]))
        if S[i] != S[-(i+1)]:
            # print("NO:{} {}".format(S[i],S[-i]))
            judge = False

    if S[0:int((len(S)-1)/2)] != S[int((len(S)+3)/2)-1:len(S)]:
        # print(S[0:int((len(S)-1)/2)])
        # print(int((len(S)-1)/2))
        # print(S[int((len(S)+3)/2)-1:len(S)])
        # print(int((len(S)+3)/2))
        judge = False


    if judge:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

int main() {
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout << ((a+d-1)/d>=(b+c-1)/b ? "Yes":"No") <<endl;
}

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

using ll = long long;

#define N 100005

int n, a[N], K, S;

int main() {
	scanf("%d %d %d", &n, &K, &S);
    for (int i = 1; i <= K; i ++) a[i] = S;
    if (S > n) fill(a+K+1, a+n+1, 1);
    else fill(a+K+1, a+n+1, 1000000000);
    for (int i = 1; i <= n; i ++) cout << a[i] << " "; cout << endl;
	return 0;
}


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

int main() {
  vector<int> S(3);

  for(int i=0;i<3;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());

  if( ( S.at(0)==S.at(1) && S.at(1)!=S.at(2) ) || S.at(1)==S.at(2) && S.at(1)!=S.at(0) ) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			while (true)
			{
				string s = Console.ReadLine();
				string[] sar = s.Split(' ');
				int n = int.Parse(sar[0]);
				int x = int.Parse(sar[1]);
				if (n == 0 && x == 0) { break;}
				int count = 0;
				for (int i = 0; i < n; i++)
				{
					for (int j = i+1; j < n; j++)
					{
						for (int k = j+1; k < n; k++)
						{
							if (i + j + k + 3 == x) { count++; }
						}
					}
				}
				Console.WriteLine(count);
			}
		}
	}
}

Measured memory_bytes: 9100
# -*- coding: utf-8 -*-
import math
num = int(raw_input())
for i in range(num):
    list = [int(x) for x in raw_input().split(" ")]
    list.sort(lambda n1, n2:n2 - n1)
    if list[0]**2 == list[1]**2 + list[2]**2:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 4372
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();
        long[] nums = new long[N];
        for (int i = 0; i < N; i++) {
            nums[i] = sc.nextLong();
        }
        Arrays.sort(nums);
        long ans = nums[0];
        if (ans == 0) {
            System.out.println(0);
        } else {
            boolean over = false;
            for (int i = 1; i < N; i++) {
                ans *= nums[i];
                if (1000000000000000000L < ans || ans <= 0) {
                    System.out.println(-1);
                    over = true;
                    break;
                }
            }
            if (!over) {
                System.out.println(ans);
            }
        }
    }
}

Measured memory_bytes: 61856
// Short Phrase(短句)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		n := nextInt(sc)
		if n == 0 {
			break
		}

		var words []string
		for i := 0; i < n; i++ {
			words = append(words, nextString(sc))
		}

		res := 0
		for i := 0; i < n; i++ {
			tmpWords := words[i:]
			ok := checkRule(tmpWords, 0)
			if ok {
				res = i + 1
				break
			}
		}

		fmt.Println(res)
	}
}

var rule = [5]int{5, 7, 5, 7, 7}

func checkRule(words []string, depth int) bool {
	var shortPhrase = ""
	var i = depth

	if depth == 5 {
		return true
	}

	for len(words) > 0 {
		shortPhrase += words[0]
		words = words[1:]

		if rule[i] == len(shortPhrase) {
			return checkRule(words, i+1) // 短句のルールを満たしたので次の文節へ
		} else if rule[i] < len(shortPhrase) {
			return false // 文節の語数オーバー
		}
	}

	return false // 文節を満たす単語が足りない
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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



Measured memory_bytes: 1172
n = gets.chomp.to_i
a = []
n.times do
  a.push gets.chomp
end

if a.size != a.uniq.size
  puts 'No'
  exit
end

(n-1).times do |i|
  if a[i].split(//).last != a[i+1].split(//).first
    puts 'No'
    exit
  end
end

puts 'Yes'


Measured memory_bytes: 1788
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define PI 3.14159265358979323846264338327950288
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)
typedef long long ll;
using namespace std;

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	ll cnt[100010] = { 0 };
	ll sum = 0;

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

	ll Q;
	cin >> Q;
	vector<ll>B(Q), C(Q);

	for (ll i = 0; i < Q; i++) {
		cin >> B[i] >> C[i];
	}

	for (ll i = 0; i < Q; i++) {
		if (cnt[B[i]] != 0) {
			sum += (C[i] - B[i]) * cnt[B[i]];
			cnt[C[i]] += cnt[B[i]];
			cnt[B[i]] = 0;
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 6388
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		boolean[] flg1 = new boolean[n];
		boolean[] flgN = new boolean[n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (a == 1) {
				flg1[b] = true;
			}
			if (b == n) {
				flgN[a] = true;
			}
		}
		sc.close();

		for (int i = 2; i < n; i++) {
			if (flg1[i] && flgN[i]) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
	}
}


Measured memory_bytes: 93336
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N, T;
  cin >> N >> T;
  vector<pll> AB(N);
  for (ll i = 0; i < N; ++i) {
    cin >> AB.at(i).first >> AB.at(i).second;
  }
  sort(AB.begin(), AB.end(), [] (pll A, pll B) {
    return A.first < B.first;
  });
  vector<ll> dp(T + 1, 0);
  for (ll i = 0; i < N; ++i) {
    ll a = AB.at(i).first, b = AB.at(i).second;
    vector<ll> temp_dp = dp;
    for (ll j = 0; j < T; ++j) {
      ll now = dp.at(j);
      ll check = min(T, j + a);
      temp_dp.at(check) = max(dp.at(check), now + b);
    }
    dp = temp_dp;
  }
  ll ans = dp.at(T);
  // for (ll i = 0; i <= T; ++i) {
  //   ans = max(ans, dp.at(i));
  // }
  cout << ans << "\n";
  // for (ll i = 0; i <= T; ++i) {
  //   cout << i << ' ' << dp.at(i) << "\n";
  // }
}


Measured memory_bytes: 512
K = int(input())

lun = list(range(0, 10)) + [0] * (K - 9 + 2) # lun[0]はダミー
k = 10

for i in range(1, K):
    if k > K: break
    next = lun[i]
    dig = next % 10  # 1の位
    if dig == 0: # 次の桁は0か1
        lun[k] = next * 10
        lun[k + 1] = next * 10 + 1
        k += 2
    elif dig == 9: # 次の桁は8か9
        lun[k] = next * 10 + 8
        lun[k + 1] = next * 10 + 9
        k += 2
    else:  # 次の桁はdig-1かdigかdig+1
        lun[k] = next * 10 + dig - 1
        lun[k + 1] = next * 10 + dig
        lun[k + 2] = next * 10 + dig + 1
        k += 3

print(lun[K])


Measured memory_bytes: 7084
main = getLine >> interact (f 0 0 0 . map read . words)

f x y z []
  | y + 2 > x + t = "Yes"
  | otherwise = "No"
    where t = if z > 0 then 1 else 0
f x y z (a:as)
  | odd a = f (succ x) y z as
  | a `mod` 4 == 0 = f x (succ y) z as
  | otherwise = f x y (succ z) as

Measured memory_bytes: 2428
#include <bits/stdc++.h>
    #define rep(i,n) for(int i = 0; i < (n); i++)
     
    using namespace std;  
    
    int main() {
   
     char a[3];
     
     rep(i,3) cin >> a[i];
     
     if(a[1]=='7' || a[0] == '7' || a[2] == '7') cout << "Yes" << '\n';
     else cout << "No" << '\n';
    
     
     return 0;
    }

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<lint> a(n + 1);
    lint tot = 0;
    for (int i = 0; i < n + 1; ++i) {
        cin >> a[i];
        tot += a[i];
    }
    if (n == 0) {
        if (a[0] != 1)
            cout << -1 << "\n";
        else
            cout << 1 << "\n";
        return 0;
    }
    if (a[0] != 0) {
        cout << -1 << "\n";
        return 0;
    }
    vector<lint> b(n + 1, 0);
    b[n]     = a[n];
    b[n - 1] = a[n];
    for (int i = n - 2; i >= 0; --i) {
        b[i] = a[i + 1] + b[i + 1];
    }
    vector<lint> c(n + 1, 0);
    c[0] = 1;
    for (int i = 1; i <= n; ++i) {
        c[i] = c[i - 1] * 2 - a[i];
        if (c[i] < 0) {
            cout << -1 << "\n";
            return 0;
        }
        c[i] = min(b[i], c[i]);
    }
    lint ret = 0;
    for (int i = 0; i <= n; ++i) {
        ret += c[i] + a[i];
    }
    ret -= c[n];
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 5560
R,C = map(int,input().split())
sy,sx = 2,2
gy,gx = R+1,C+1

maze = [["#"]*(C+2)]
white_count = 0
for i in range(R):
    temp = list(input())
    temp.insert(0,'#')
    temp.append('#')
    maze.append(temp)
    white_count += temp.count('.')
    
maze.append(["#"]*(C+2))
#print(maze)
vx = [0,1,0,-1]
vy = [1,0,-1,0]
Q = [[sy-1,sx-1,0]]

checked = [[sy-1,sx-1]]
while True:
   if len(Q) == 0:
       length = white_count+1
       break
   now = Q.pop(0)
   if now[0] == gy-1 and now[1] == gx-1:
       length = now[2]+1
       break
   for i in range(4):
       next_y = now[0]+vy[i]
       next_x = now[1]+vx[i]
       if not [next_y,next_x] in checked and maze[next_y][next_x] == '.':
           checked.append([next_y,next_x])
           Q.append([next_y,next_x,now[2]+1])      
print(white_count-length) 



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int mod=998244353,N=4e5+9;
int f[N],iv[N];
int pw(int a,int t=mod-2){
	int x=1;
	while(t){
		if(t&1)x=x*a%mod;
		a=a*a%mod,t>>=1;
	}
	return x;
}
int C(int n,int r){
	if(r==0)return 1;
	return f[n]*iv[r]%mod*iv[n-r]%mod;
}
int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);
    f[0]=1,iv[0]=1;
    for(int i=1;i<N;i++){
    	f[i]=i*f[i-1]%mod;
    	iv[i]=pw(f[i]);
    }
    int n,m,k,sum=0;
    cin >> n >> m >> k;
    for(int i=0;i<=k;i++){
    	sum=(sum+m*pw(m-1,n-1-i)%mod*C(n-1,i)%mod)%mod;
    }
    cout << sum;
}


Measured memory_bytes: 9868
#include <iostream>
#include <vector>
#include <algorithm>
#include <map> 
#include <cmath>

#define MOD 1000000007

using namespace std;
typedef long long ll;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


void calc_combinations(ll Nmax, ll k, map<ll, ll>& C) {
    C[k] = 1;
    for (ll i=k+1; i<=Nmax; i++) {
        C[i] = (((C[i-1] * i) % MOD) * modinv(i - k, MOD)) % MOD;
    }
}

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    map<ll, ll> C;
    calc_combinations(N-1, K-1, C);

    ll res = 0;
    for (int i=0; i<N-K+1; i++) {
        res += (A[i] * C[N-1-i]) % MOD;
    } 
    
    sort(A.begin(), A.end());

    for (int i=0; i<N-K+1; i++) {
        res -= (A[i] * C[N-1-i]) % MOD;
    } 
    res %= MOD;

    if (res < 0) res += 1000000007;

    cout << res << endl;

    return 0;

}


Measured memory_bytes: 4096
#include <stdio.h>
#include <math.h>
int ami[31][20],i,j,x,n,m,d,h;

int main(void){
	for(i=0;i<10;i++){ami[0][2*i]=i;}
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		scanf("%d %d %d",&m,&h,&d);
		m--;h--;
		for(i=1;i<=d;i++){for(j=0;j<n*2;j++){ami[i][j]=-1;}}
		for(i=1;i<=d;i++){
			for(j=1;j<n*2-2;j+=2){
				scanf("%1d",&x);
				if(x==1){
					ami[i][j-1]=ami[i-1][j+1];
					ami[i][j+1]=ami[i-1][j-1];
					if(j>1)ami[i][j-2]=8;
					if(j<n*2-3)ami[i][j+2]=8;
					ami[i][j]=1;
				}else{
					if(ami[i][j-1]<0)ami[i][j-1]=ami[i-1][j-1];
					ami[i][j+1]=ami[i-1][j+1];
					if(ami[i][j]<0)ami[i][j]=0;
				}
			}
		}
		x=ami[d][h*2];
		if(x==m)printf("0\n");
		else{
			for(i=1;i<=d && x<90;i++){
				for(j=0;j<n*2 && x<90;j+=2){
					if(ami[i][j]==x){
						if(j>1 && ami[i][j-1]<1 && m==ami[i][j-2]){printf("%d %d\n",i,j/2);x=99;}
						else if(j<n*2-3 && ami[i][j+1]<1 && m==ami[i][j+2]){printf("%d %d\n",i,j/2+1);x=99;}
						break;
					}
				}
			}
			if(x<90)printf("1\n");
		}
	}
	return 0;
}

Measured memory_bytes: 608