akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////



int main(){
    ll n;string s;cin>>n>>s;
    ll dp[n][n+1];memset(dp,0,sizeof(dp));
    rep(i,0,n-1)dp[0][i]=1;
    rep(i,0,n-2){
        rep(j,0,n-1){
            if(s[i]=='<'){
                Add(&dp[i+1][0],dp[i][j]);
                Add(&dp[i+1][j],-dp[i][j]);
            }else{
                Add(&dp[i+1][j],dp[i][j]);
                Add(&dp[i+1][n-i-1],-dp[i][j]);
            }
        }
        rep(j,0,n-2)Add(&dp[i+1][j+1],dp[i+1][j]);
    }
    ll ans=0;
    /*rep(i,0,n-1){
        rep(j,0,n-1){
            cout<<dp[i][j]<<" ";
        }cout<<endl;
    }*/
    cout<<dp[n-1][0]<<endl;
    
    return 0;
}






Measured memory_bytes: 70656
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>	// upper_bound(A, A+N, num), lower_bound(A, A+N, num)
#include <functional>
#include <string>
#include <sstream>
#include <complex>
#include <vector>		// V[i],  push_back(x), pop_back(), insert(index, x), erase(index), sort(v.begin(), v.end(), greater<int>())
#include <list>			// push_front(x), push_back(x), pop_front(), pop_back(), insert(index, x)
#include <queue>		// push(x), front(), pop()
#include <deque>
#include <stack>		// push(x), top(), pop()
#include <map>			// M[key],  insert(key, val), erase(key), find(key), 
#include <set>			// insert(key), erase(key), find(key)

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

#define PI 3.141592653589793)
#define MOD 1000000007
#define REP(i, n) for(int i = 0; i < n; i++)

int N;
map<int, int> mp;

void solve() {
	cin >> N;
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if(mp[A]++) cnt++;
	}
	int ans = N - (cnt % 2 == 0 ? cnt : cnt + 1);
	cout << ans << endl;
}

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

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i, s.size()) {
        cout << s[s.size() - i - 1];
    }
    cout << "\n";
	return 0;
}


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

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

    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }

    /* 数値を大きい順にソート */
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            if (data.at(i) < data.at(j)) {
                int tmp =  data.at(i);
                data.at(i) = data.at(j);
                data.at(j) = tmp;
            }
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += pow(-1, i) * data.at(i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
      Scanner scanner = new Scanner(System.in);
		
        //文字コードを使用して次を表示
		 System.out.println((char)(scanner.next().charAt(0) + 1));
	
    }
 	
}

Measured memory_bytes: 21332
n = int(input())
ab = [list(map(int,input().split())) for i in range(n)]
from operator import itemgetter
ab = sorted(ab,key = itemgetter(1))
nowtime = 0
for i in range(n):
         nowtime += ab[i][0]
         if nowtime > ab[i][1]:
                  print("No")
                  exit()
print("Yes")


Measured memory_bytes: 55252
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include <iostream>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;
ll fact[N], inv[N];
ll ncr(int n,int r) {
	ll res = 1;
	ll fact = 2;
	for (ll i = n - r + 1; i <= n; ++i) {
		res *= i;
		if (res%fact == 0 && fact <= r) {
			res /= fact;
			fact++;
		}
	}
	return res;
}


int main() {
	int n, m,ans=0;
	cin >> n >> m;
	if (n >= 2)
		ans += ncr(n, 2);
	if (m>=2)
	ans += ncr(m, 2);
	cout << ans;
	return 0;

}


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

int main()
{
    long long int N, K, b, x = 0;
    cin >> N >> K;
    if (K == 0)
    {
        x = N * N;
        cout << x << endl;
        return 0;
    }
    for (long long int b = 1; b <= N; b++)
    {
        long long int p = N / b;
        long long int r = N % b;
        x += (b - K) > 0 ? p * (b - K) : 0;
        x += (r - K + 1) > 0 ? (r - K + 1) : 0;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())
H = H % 12

deg_A = M*6
deg_B = (H*30) + (M/2)
deg_ab = abs(deg_A-deg_B)

x = A*A + B*B - 2*A*B*math.cos(math.radians(deg_ab))
print(math.sqrt(x))

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

#define ll long long

ll gcd(ll a, ll b){
    if(b>a) return gcd(b,a);
    if(a%b!=0) return gcd(a%b, b);
    return b;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    cin >> k;

    ll sum=0;
    for(int i=1; i<=k; i++){
        for(int j=1; j<=k; j++){
            for(int p=1; p<=k; p++){
                ll x = gcd(i, gcd(j,p));
                sum+=x;
            }
        }
    }

    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int x,max,ans;
  ans = 1;
  cin >> x;
  max = x;
  
  for(int i = 1; i < N; i++){
    cin >> x;
    max = min(max,x);
    if(max>=x) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const ll INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    string s,t;
    cin >> s >> t;

    VVI exist(26);
    REP(i,s.size()) exist[s[i]-'a'].push_back(i);

    if(exist[t[0]-'a'].size() == 0){cout << "-1" << endl; return 0;}
    ll idx = exist[t[0]-'a'][0];
    ll top = 0, next;
    FOR(i,1,t.size()){
        if(exist[t[i]-'a'].empty()){cout << "-1" << endl; return 0;}
        else if(exist[t[i]-'a'].size() == 1) next = exist[t[i]-'a'][0];
        else{
            if(exist[t[i]-'a'][0] > idx) next = exist[t[i]-'a'][0];
            else if(exist[t[i]-'a'][exist[t[i]-'a'].size()-1] <= idx) next = exist[t[i]-'a'][0];
            else{
                int l = 0, r = exist[t[i]-'a'].size()-1;
                int n = (l+r)/2;
                while(r-l > 1){
                    if(exist[t[i]-'a'][n] <= idx) l = n;
                    else r = n;
                    n = (l+r)/2;
                }
                next = exist[t[i]-'a'][r];
            }
        }
        if(idx >= next) top++;
        idx = next;
    }
    ll size = (ll)s.size();
    ll ans = top*size + idx+1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1216
N, M = map(int, input().split())
p_list = [1 for _ in range(N)]
e_list = list(map(int, input().split()))
for _ in range(M):
    a, b = map(int, input().split())
    if e_list[a - 1] <= e_list[b - 1]:
        p_list[a - 1] = 0
    if e_list[b - 1] <= e_list[a - 1]:
        p_list[b - 1] = 0
print(sum(p_list))

Measured memory_bytes: 20812
/* BISMILLAHIR RAHMANIR RAHIM */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    ll x = c - a - b, y = 4 * a * b;
    if( x < 0 ) {
        cout << "No";
        exit(0);
    }
    cout << (x * x > y ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define mem0(a) memset(a,0,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define pn putchar('\n')
#define ps putchar(' ')
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N=1e5+5;

map<ll,ll>mp;
int main()
{
for(int i=1;i<=9;i++)
for(int j=1;j<=9;j++)
mp[i*j]=1;
ll n;
cin>>n;
printf("%s",mp[n]?"Yes":"No");
}





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

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  int A, B;
  cin >> A >> B;
  if(B%A == 0) cout << A + B << endl;
  else cout << B-A << endl;
  return 0;
}


Measured memory_bytes: 3584
n=int(input())
a=list(map(int,input().split()))


while(1):
    count=0
    mina=1000000000+1
    for j in range(len(a)):
        if mina>a[j] and a[j]!=0:
            mina=a[j]
            #print(mina)

    for i in range(len(a)):
        if a[i]==mina and count==0:
            count+=1
        else:
            a[i]=a[i]%mina
    #print(a)
    maxa=max(a)
    if sum(a)==maxa:
        print(maxa)
        break


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define PI (acos(-1))

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

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 int MAXM=100010;
int n,m;
vector<int> xy[MAXM];

int dp[MAXM];
int flag[MAXM];

int f(int x){
  if(flag[x]) return dp[x];
  flag[x]=1;
  int res=0;
  for(auto e: xy[x]){
    chmax(res, f(e)+1);
  }
  dp[x]=res;
  return res;
}

signed main()
{
  cin>>n>>m;
  rep(i,m){
    int x,y; cin>>x>>y;
    xy[x].push_back(y);
  }
  int ans=0;
  reps(i,n){
    chmax(ans, f(i));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8576
import java.io.*;
import java.util.Arrays;
import java.util.stream.IntStream;

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

  private void run() {
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out)) {

      final int MAX = 100000;
      int n = Integer.parseInt(in.readLine());

      int[] table = new int[MAX+1];
      in.lines()
        .limit(n)
        .map(s -> s.split(" "))
        .map(a -> Arrays.stream(a).mapToInt(Integer::parseInt).toArray())
        .forEach(a -> IntStream.rangeClosed(a[0],a[1])
          .parallel()
          .forEach(i -> table[i] = 1)
        );

      final int ans = Arrays.stream(table).sum();
      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 31684
n = int(input())
j = 0
data = [0] * n
i = 2
while j < n:
    divcnt = 0
    for k in range(1, i * 5 + 2):
        if (i * 5 + 1) % k == 0:
            divcnt += 1
        
    if divcnt == 2:
        data[j] = i * 5 + 1
        j += 1
    
    i += 1
    
for i in range(n):
    print("{0} ".format(data[i]), end = "")


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

int main(){
    int n;
    while( cin >> n, n ){
        long long sheet[n+1][n+1];
        int i, j;
        for(i = 0; i < n; i++){
            for(j = 0; j < n; j++){
                cin >> sheet[i][j];
            }
        }
        int ss = 0;
        for(i = 0; i < n; i++){
            int s = 0;
            for(j = 0; j < n; j++){
                s += sheet[i][j];
            }
            sheet[i][n] = s;
            ss += s;
        }
        sheet[n][n] = ss;
        for(i = 0; i < n; i++){
            int s = 0;
            for(j = 0; j < n; j++){
                s += sheet[j][i];
            }
            sheet[n][i] = s;
        }
        for(i = 0; i <= n; i++){
            printf("%5lld", sheet[i][0]);
            for(j = 1; j <= n; j++){
                printf("%5lld", sheet[i][j]);
            }
            cout << endl;
        }
    }
    return 0;
}

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

int dp[2][100000];
int main() 
{
	string s; cin>>s;
	int i=0,j=s.length()-1;
	int cnt=0;
	while(i<=j)
	{
		if(s[i]!=s[j])
		{
			cnt++;
		}
		i++; j--;
		
	}
	cout<<cnt;
	
	
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int N, X, T;
    cin >> N >> X >> T;
    int r = ceil(N/(double)X);
    cout <<  r* T << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
int N;
void dfs(string s,char MAX){
  if(s.size()==N){
    cout<<s<<endl;
    return;
  }
  for(char c='a';c<=MAX+1;c++){
    string t=s;
    t+=c;
    char m=max(c,MAX);
    dfs(t,m);
  }
}


int main() {
  cin>>N;
  dfs("",'a'-1);
  return 0;
}

Measured memory_bytes: 3620
class Array
  def diff; s = self[0]; self[1...(self.size)].map{|k|d=k-s; s=k; d} end
end

k,n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

ans = k - a.push(k+a[0]).diff.max

puts ans

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

struct UnionFind{
    vector<int>parent;//親の番号
    UnionFind(int N):parent(N){
        rep(i,N){
            parent[i]=i;
        }
    }//全て根であるとして初期化
    int root(int x){
        if(parent[x]==x){
            return x;
        }
        return parent[x]=root(parent[x]);
    }//根を探す
    void unite(int x,int y){
        int rx=root(x);
        int ry=root(y);
        if(rx==ry){
            return;
        }
        parent[rx]=ry;
    }//xの根をyの根にくっつける
    bool same(int x,int y){
        int rx=root(x);
        int ry=root(y);
        return rx==ry;
    }//x,yの属する木が同じならtrue
};

int main(){
    int N,M,K;cin>>N>>M>>K;
    vector<set<int>>F(N);
    UnionFind tree(N);
    vector<int>Groupnumber(N);
    rep(i,M){
        int a,b;cin>>a>>b;
        a--;b--;
        tree.unite(a,b);
        F[a].insert(b);
        F[b].insert(a);
    }
    rep(i,K){
        int a,b;cin>>a>>b;
        a--;b--;
        if(tree.same(a,b)){
            F[a].insert(b);
            F[b].insert(a);
        }
    }
    rep(i,N){
        int k=tree.root(i);
        Groupnumber.at(k)+=1;
    }
    rep(i,N){
        int k=tree.root(i);
        cout<<Groupnumber.at(k)-1-F[i].size()<<" ";
    }
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int64 dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int64 dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

int main(void) {
  int64 n, w, d;
  while (cin >> n >> w >> d && n+w+d) {
    vector<PLL> sq({PLL(w*d, w)}); // area, width
    REP(i, n) {
      int64 p, s;
      cin >> p >> s; p--;
      int64 w, h;
      w = sq[p].sc; h = sq[p].fs/w;
      sq.erase(sq.begin()+p);
      PLL a[2];
      s %= (2*(w+h));
      if ((0 <= s && s < w) || (h+w <= s && s <= h+2*w)) {
        s %= h+w;
        a[0] = PLL(s*h, s); a[1] = PLL(w*h-s*h, w-s);
      } else {
        s -= w; s %= h+w;
        a[0] = PLL(w*s, w); a[1] = PLL(w*h-w*s, w);
      }
      sort(a, a+2);
      sq.push_back(a[0]);
      sq.push_back(a[1]);
    }
    sort(all(sq));
    REP(i, sq.size()) {
      cout << sq[i].fs << " \n"[i == sq.size()-1];
    }
  }
}



Measured memory_bytes: 3012
S = input()

def hasC(txt):
    c = 0
    for t in txt:
        if t == "C":
            if c > 0:
                return False
            c = 1
    return c == 1
def allLower(txt):
    a = ord("a")
    z = ord("z")
    for t in txt:
        tc = ord(t)
        if tc < a or tc > z:
            return False
    return True

if S[0] != "A":
    print("WA")
    exit()
if not hasC(S[2:-1]):
    print("WA")
    exit()
nonC = S[:2] + S[2:-1].replace("C", "") + S[-1]
if not allLower(nonC[1:]):
    print("WA")
    exit()
print("AC")

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.next());
        int minDivideCount = Integer.MAX_VALUE;
        for (int i = 0; i < num; i++) {
            int count = Integer.numberOfTrailingZeros(sc.nextInt());
            if (minDivideCount > count) {
                minDivideCount = count;
            }
        }

        System.out.println(minDivideCount);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#include <bitset>
#include <math.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 10007;
const int INF = LLONG_MAX/3;
const int MAX = 710000;

/*-----Library-----*/

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/*-----Library-----*/
int cost[100100];
int n;
struct edge{
    int to;
    int cost;
};
vector<edge> es[100100];
bool used[100100]={};
void dfs(int s){
    used[s]=true;
    for(int i=0;i<es[s].size();i++){
        if(used[es[s][i].to]==false){
            cost[es[s][i].to]=cost[s]+es[s][i].cost;
            dfs(es[s][i].to);
        }
    }
}
signed main(){
    cin>>n;
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        edge e;
        e.to=b-1;
        e.cost=c;
        es[a-1].push_back(e);
        e.to=a-1;
        es[b-1].push_back(e);
    }
    int q,k;
    cin>>q>>k;
    k--;
    cost[k]=0;
    dfs(k);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        cout<<cost[x-1]+cost[y-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 15232
#include <iostream>
#include <algorithm>
#define INF 1000000000
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,k;
  int h[100005];
  int dp[100005]={};
  int m;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  for(int i=1;i<n;i++){
    if(i==1){
      dp[i]=abs(h[i]-h[i-1]);
    }
    else{
      m=INF;
      for(int j=1;j<=k;j++){
	if(m>abs(h[i]-h[i-j])+dp[i-j]){
	  m=abs(h[i]-h[i-j])+dp[i-j];
	}
	if(i-j==0){
	  j+=k;
	}
      }
      dp[i]=m;
    }
  }
  cout<<dp[n-1]<<"\n";

  return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>

int main() {
    long long X;
    int ans = 1000;
    scanf("%lld", &X);
    while(X > 99) {
        int t = X % 1000;
        if(abs(753-t) < ans) {
            ans = abs(753-t);
        }
        X /= 10;
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
class BellmanFord:
    """Bellman-Ford algorithm : find the shortest path from a vertex
       Complexity: O(VE)
       used in GRL1A(AOJ)
    """

    def __init__(self, V, E, start, INF=10**9):
        """ V: the number of vertexes
            E: adjacency list (all edge in E must be 0 or positive)
            start: start vertex
            INF: Infinity distance
        """
        self.V = V
        self.E = E
        self.bellman_ford(start, INF)

    def bellman_ford(self, start, INF):
        self.distance = [INF] * self.V # distance from start
        self.prev = [-1] * self.V # prev vertex of shortest path
        self.distance[start] = 0
        self.negativeCycle = False
        
        for i in range(V):
            update = False
            for v in range(V):
                for to, cost in self.E[v]:
                    if self.distance[v] != INF and self.distance[v] + cost < self.distance[to]:
                        self.distance[to] = self.distance[v] + cost
                        self.prev[to] = v
                        update = True
                        if i == V - 1:
                            self.negativeCycle = True
            if update == False:
                break

    def getPath(self, end):
        assert self.hasNegativeCycle() == False
        path = [end]
        while self.prev[end] != -1:
            end = self.prev[end]
        return path[::-1]

    def hasNegativeCycle(self):
        return self.negativeCycle

V, E, r = map(int, input().split())
INF = 10**9
edge = [[] for _ in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    edge[s].append((t, d))

sp = BellmanFord(V, edge, r, INF)
if sp.hasNegativeCycle():
    print('NEGATIVE CYCLE')
else:
    for dist in sp.distance:
        print(dist if dist != INF else 'INF')

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

map<string, bool> dic;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    
    int n;
    cin >> n;
    
    rep(i,n){
        string s,t;
        cin >> s >> t;
        
        if(s=="insert"){
            dic[t] = true;
        } else {
            if(dic[t]) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 47472
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
    double r;
    cin >> r;
    double menseki = r * r * M_PI;
    double syu = r * 2 * M_PI;

    cout << fixed << setprecision(6) << menseki << " ";
    cout << fixed << setprecision(6) << syu << endl;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    char c,priv;
    int pp=1;

    cin >> c;
    priv = c;

    for(int i=1; i<n; i++){
        cin >> c;
        if(priv != c){
            pp++;
        }
        priv = c;
    }
    for(int i=0; i<k; i++){
        if(pp > 2){
            pp -= 2;
        }else if(pp == 2){
            pp--;
        }else if(pp == 1){
            break;
        }
    }
    cout << n-pp << endl;
}

Measured memory_bytes: 256
# Acceptance of input

import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

adj_mat = [[0] * V for i in range(V)]

for line in file_input:
    u, v, c = map(int, line.split())
    adj_mat[u][v] = c

# Ford???Fulkerson method

import collections

# BFS for residual capacity network
def bfs(start, goal, parent):
    unvisited = [True] * V
    queue = collections.deque()
    queue.append(start)
    unvisited[start] = False
    while queue:
        u = queue.popleft()
        for v, r_capacity in enumerate(adj_mat[u]):
            if unvisited[v] and (r_capacity > 0):
                queue.append(v)
                unvisited[v] = False
                parent[v] = u
                if v == goal:
                    return not unvisited[goal]

def ford_fulkerson(source, sink):
    parent = [None] * V
    max_flow = 0
    while bfs(source, sink, parent):
        aug_path_flow = 10000
        v = sink
        while (v != source):
            aug_path_flow = min(aug_path_flow, adj_mat[parent[v]][v])
            v = parent[v]
        max_flow += aug_path_flow
        v = sink
        while (v != source):
            u = parent[v]
            adj_mat[u][v] -= aug_path_flow
            adj_mat[v][u] += aug_path_flow
            v = u
    return max_flow

# output
print(ford_fulkerson(0, V - 1))

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

int main(){
  	int N;
  	cin>>N;
  	vector<double> A(N);
  	for(int i=0;i<N;i++){
    	cin>>A[i];
    }
  	vector<vector<double>> dp(N+1,vector<double>(N+1,0.0));
  	dp[1][0]=1.0-A[0];
  	dp[1][1]=A[0];
  	for(int i=2;i<=N;i++){
    	for(int j=0;j<=i;j++){
        	if(j==0)	dp[i][j]=dp[i-1][j]*(1.0-A[i-1]);
          	else{
            	dp[i][j]= dp[i-1][j]*(1.0-A[i-1]) + dp[i-1][j-1]*A[i-1];
            }
        }
    }
  	double ans=0.0;
	for(int i=(N+1)/2;i<=N;i++){
      	ans+=dp[N][i];
    }
  	cout<<setprecision(10)<<ans;
	return 0;
}

Measured memory_bytes: 73800
import java.util.Scanner;
import java.util.InputMismatchException;

class Main {
   public static void main(String args[]) {
      int N=0;
      int[] p;
      Scanner scanner = new Scanner(System.in);
      N = scanner.nextInt();
      p = new int[N];
      for (int i=0; i<N; i++) {
         p[i] = scanner.nextInt();
      }
      scanner.close();
      int flag = 0;
      for (int k = 0; k<N-1; k++) {
         for (int i=k+1; i<N; i++) {
            if (p[i] < p[k]) {
               flag = 1;
               break;
            }
         }
      }
      if (flag == 0) {
         System.out.println("YES");
      } else {
         int flag2 = 0;
         int flag3 = 0;
         for (int i= 0; i<N-1; i++) {
            for (int j=i+1; j<N; j++) {

               int tmp = p[i];
               p[i] = p[j];
               p[j] = tmp;
               for (int k = 0; k<N-1; k++) {
                  for (int l=k+1; l<N; l++) {
                     if (p[l] < p[k]) {
                        flag2 = 1;
                        break;
                     }
                  }
               }
               // for (int k = 0; k<N; k++) {
               //    System.out.println(p[k]);
               // }
               // System.out.println();
               if (flag2 == 0) {
                  System.out.println("YES");
                  flag3 = 1;
                  break;
               }
               p[j] = p[i];
               p[i] = tmp;
               flag2 = 0;
            }
            if (flag3 == 1) {
               break;
            }
         }

         if (flag3 == 0) {
            System.out.println("NO");
         }

      }

   }
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

    int n;
    cin >> n;

    if(n == 1){
        cout << 1;
        return 0;
    }

    int cur, prev, cnt = 1, dir = 0;

    cin >> prev;

    for(int i = 1; i < n; ++i){
        cin >> cur;

        if(prev < cur){
            if(dir == -1){
                dir = 0;
                cnt++;
            } else {
                dir = 1;
            }
        } else if(prev > cur){
            if(dir == 1){
                dir = 0;
                cnt++;
            } else {
                dir = -1;
            }
        }

        prev = cur;
    }

    cout << cnt;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
const int INT_MIN=-1e9;
int a[5000];
int left[5010],right[5010];
int main(){
	int n,i;
	while(scanf("%d",&n),n){
		memset(a,0,sizeof(a));
		memset(left,0,sizeof(left));
		memset(right,0,sizeof(right));
		for(i=0;i<n;i++){
			scanf("%d",&a[i]);
		}
		left[0]=0;
		for(i=1;i<n;i++){
			left[i]=left[i-1]+a[i-1]>0?left[i-1]+a[i-1]:0;
		}
		right[n-1]=0;
		for(i=n-2;i>=0;i--){
			right[i]=right[i+1]+a[i+1]>0?right[i+1]+a[i+1]:0;
		}
		int ans=INT_MIN;
		for(i=0;i<n;i++){
			ans=ans>left[i]+a[i]+right[i]?ans:left[i]+a[i]+right[i];
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

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

int main() {
    int N, l, r, ans = 0;
    cin >> N;
    rep(i, N) {
        cin >> l >> r;
        ans += abs(l-r) + 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//メモリ数確認したか?
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<math.h>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long int ll;

int main()
{
    int N,K;
	int C[2000],G[2000];
	vector<int>X[10];
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++){
		scanf("%d%d",&C[i],&G[i]);
		X[G[i]-1].push_back(C[i]);
	}
	for(int i=0;i<10;i++){
		sort(X[i].begin(),X[i].end());
		reverse(X[i].begin(),X[i].end());
	}
	int sum[10][2001];
	for(int i=0;i<10;i++){
		sum[i][0]=0;
		for(int j=1;j<=X[i].size();j++){
			sum[i][j]=sum[i][j-1]+X[i][j-1]+2*(j-1);
		}
	}
	int dp[2001];
	fill(dp,dp+N+1,0);
	for(int i=0;i<10;i++){
		for(int j=2000-X[i].size();j>=0;j--){
			for(int k=0;k<=X[i].size();k++){
				dp[j+k]=max(dp[j+k],dp[j]+sum[i][k]);
			}
		}
	}
	printf("%d\n",dp[K]);
    return 0;
}
//メモリ数確認したか?

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

const int kNmax = 150;
const int kInf = 0x3f3f3f3f;

int a, b, c, best[kNmax][kNmax][kNmax];

int main() {
    cin >> a >> b >> c;
    memset(best, kInf, sizeof(best));
    best[a][b][c] = 0;
    
    for (int sum = a + b + c; sum < 3 * kNmax; sum++) {
        for (int nra = a; nra < kNmax && nra <= sum; nra++) {
            for (int nrb = b; nrb < kNmax && nra + nrb <= sum; nrb++) {
                int nrc = sum - nra - nrb;
                if (nrc < c || nrc >= kNmax) continue;
                if (nra + 2 < kNmax) best[nra + 2][nrb][nrc] = min(best[nra + 2][nrb][nrc], best[nra][nrb][nrc] + 1);
                if (nrb + 2 < kNmax) best[nra][nrb + 2][nrc] = min(best[nra][nrb + 2][nrc], best[nra][nrb][nrc] + 1);
                if (nrc + 2 < kNmax) best[nra][nrb][nrc + 2] = min(best[nra][nrb][nrc + 2], best[nra][nrb][nrc] + 1);
                if (nra + 1 < kNmax && nrb + 1 < kNmax) best[nra + 1][nrb + 1][nrc] = min(best[nra + 1][nrb + 1][nrc], best[nra][nrb][nrc] + 1);
                if (nra + 1 < kNmax && nrc + 1 < kNmax) best[nra + 1][nrb][nrc + 1] = min(best[nra + 1][nrb][nrc + 1], best[nra][nrb][nrc] + 1);
                if (nrb + 1 < kNmax && nrc + 1 < kNmax) best[nra][nrb + 1][nrc + 1] = min(best[nra][nrb + 1][nrc + 1], best[nra][nrb][nrc] + 1);
            }
        }
    }
    
    int res = kInf;
    for (int i = 0; i < kNmax; i++) {
        res = min(res, best[i][i][i]);
    }
    cout << res << "\n";
}

Measured memory_bytes: 13440
import sys
input = sys.stdin.readline

n,m = map(int, input().split())
a = list(map(int, input().split()))
cb = [list(map(int,input().split()))[::-1] for _ in range(m) ]
cb.append([-1,1])

a.sort()
cb.sort()

i= n-1
j = m

ans = 0
remain = n
while(remain > 0):
    if( a[i] > cb[j][0] ):
        ans += a[i]
        i -= 1
        remain -= 1
    else:
        ans += cb[j][0] * min(remain, cb[j][1])
        remain -= cb[j][1]
        j -= 1

print(ans)


Measured memory_bytes: 68120
#include <iostream>
using namespace std;
   
int F[102][102];
int xg,yg,w,h;
   
   
void DFS(int Y,int X,int c){
  //if(Y < 1 || X < 1)
    //return;
  if(F[Y][X] != c){
    return;
  }
   
  F[Y][X] = -1;
  DFS(Y+1,X  ,c);
  DFS(Y-1  ,X,c);
  DFS(Y,X+1  ,c);
  DFS(Y  ,X-1,c);
}
   
   
int main(){
  int xs,ys,n;
  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0)
      break;
for(int i=0; i<102; i++){
      for(int j=0; j<102; j++){
        F[i][j] = 10;
      }
    }
       F[0][-1] = 0;
    cin >> xs >> ys >> xg >> yg >> n;
   
   
    for(int i=0;i<n;i++){
      int c,d,x,y;
      cin >> c >> d >> x >> y;
      if(c == 0)
         c = 1919810;
      if(d == 0){
        for(int j=0;j<4;j++){
          F[x+j][y] = c;
          F[x+j][y+1] = c;
        }
      } else {
        for(int j=0;j<4;j++){
          F[x][y+j] = c;
          F[x+1][y+j] = c;
        }
      }
    }
  DFS(xs,ys,F[xs][ys]);
   
  if(F[xg][yg] == -1){
    cout << "OK" << endl;
  } else {
    cout << "NG" <<endl;
  }
  }
}


Measured memory_bytes: 3764
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z->key < x->key ) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if ( y == NIL ) {
    root = z;
  } else {
    if ( z->key < y->key ) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node *u) {
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node *u) {
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main() {
  int n, i, x;
  string com;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    cin >> com;
    if ( com == "insert" ) {
      scanf("%d", &x);
      insert(x);
    } else if ( com == "print" ) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Measured memory_bytes: 26724
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define fr(i,a,b) for(int i = a ; i < b ; ++i)
#define backfr(i,a,b) for(int i = a ; i > b ;--i)
#define all(v) v.begin() , v.end()
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define show(x) cout << #x <<" = " << x << endl
#define fastio ios_base::sync_with_stdio(0)

typedef long long ll;
typedef vector < int > vi;
typedef vector < vector <int > > vvi;
typedef pair <int , int > ii;
typedef vector < pair <int , int> > vii;

int main()
{
	fastio;cin.tie(0);cout.tie(0);
	int h ,a , count=0;
	cin>>h>>a;
	while(h>0)
	{
		h=h-a;
		++count;
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if a == b:
  print("YES")
elif a < b:
  a_new = a + v * t
  b_new = b + w * t
  if a_new >= b_new:
    print("YES")
  else:
    print("NO")
else:
  a_new = a - v * t
  b_new = b - w * t
  if a_new <= b_new:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
        cout.tie(0);
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i;j<=n;j+=i)
		ans+=j;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#define N 10000
#define M 2000001

int num;
void CountingSort(int [ ], int [ ], int );

int main()
{

  int i=0,maxn=0,A[M],B[M];

  while(1)
    {
      scanf("%d",&num);
      if(num >= 1 && num <= M)
	  break;
    }

  while(i<num)
    {
      scanf("%d",&A[i]);
      if(A[i] >= 0 && A[i] <= N)
	{
	  if(maxn < A[i]) maxn = A[i];
	  i++;
	}
    }
  CountingSort(A,B,maxn);

  for(i=0;i<num-1;i++)
      printf("%d ",B[i]);
  printf("%d\n",B[i]);
  
  return 0;
}


void CountingSort(int a[], int b[], int k)
{
  int i,j,C[M];

  //C = malloc(sizeof(int) * k + 1);

  for(i=0;i<=k;i++)
    C[i] = 0;

  for(j=0;j<num;j++)
    C[a[j]]++;

  for(i=1;i<=k;i++)
    C[i] += C[i-1];

  for(j=num-1;j>=0;j--)
    {
      b[C[a[j]]-1] = a[j];
      C[a[j]]--;
    }
  //free(C);
}



Measured memory_bytes: 17384
class Combination:
    """階乗とその逆元のテーブルをO(N)で事前作成し、組み合わせの計算をO(1)で行う"""
    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [0] * (n + 1)
        self.inv_fact[n] = pow(self.fact[n], MOD - 2, MOD)
        for i in reversed(range(n)):
            self.inv_fact[i] = self.inv_fact[i + 1] * (i + 1) % MOD
        self.MOD = MOD

    def factorial(self, k):
        """k!を求める O(1)"""
        return self.fact[k]

    def inverse_factorial(self, k):
        """k!の逆元を求める O(1)"""
        return self.inv_fact[k]

    def permutation(self, k, r):
        """kPrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r]) % self.MOD

    def combination(self, k, r):
        """kCrを求める O(1)"""
        if k < r:
            return 0
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD

    def combination2(self, k, r):
        """kCrを求める O(r) kが大きいが、r <= nを満たしているときに使用"""
        if k < r:
            return 0
        res = 1
        for l in range(r):
            res *= (k - l)
            res %= self.MOD
        return (res * self.inv_fact[r]) % self.MOD


n, a, b, k = map(int, input().split())
MOD = 998244353
comb = Combination(10 ** 6, MOD)

ans = 0
for cnt_a in range(0, n + 1):
    point = a * cnt_a
    nokori = k - point
    if nokori >= 0 and nokori % b == 0:
        cnt_b = nokori // b
        if cnt_b > n:
            continue
        ans += comb.combination(n, cnt_a) * comb.combination(n, cnt_b)
        ans %= MOD
print(ans % MOD)

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

void solve(long long L, long long R, long long d)
{
    long long cnt = 0;
    for (long long i = L; i <= R; i++)
    {
        if (i % d == 0)
            cnt++;
    }
    cout << cnt << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long L;
    scanf("%lld", &L);
    long long R;
    scanf("%lld", &R);
    long long d;
    scanf("%lld", &d);
    solve(L, R, d);
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>

using namespace std;

#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

void merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    Card L[n1];
    Card R[n2];
    for (int i = 0; i < n1; ++i) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; ++i) {
        R[i] = A[mid + i];
    }
    L[n1].value = SENTINEL;
    R[n2].value = SENTINEL;
    int i = 0;
    int j = 0;
    for (int k = left; k < right; ++k) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort(Card A[], int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(Card A[], int p, int r) {
    Card t;
    Card x;
    x = A[r];
    int i = p - 1;
    for (int j = p; j < r; ++j) {
        if (A[j].value <= x.value) {
            ++i;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(Card A[], int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q - 1);
        quickSort(A, q + 1, r);
    }
}

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

    Card A[n];
    Card B[n];
    char S[10];
    int v;
    for (int i = 0; i < n; ++i) {
        scanf("%s %d", S, &v);
        A[i].suit = S[0];
        B[i].suit = S[0];
        A[i].value = v;
        B[i].value = v;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n - 1);

    bool stable = true;
    for (int i = 0; i < n; ++i) {
        if (A[i].suit != B[i].suit) {
            stable = false;
        }
    }

    if (stable) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
    
    for (int i = 0; i < n; ++i) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}

Measured memory_bytes: 5532
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 2147483647;
int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE];
bool is_a[TREE_SIZE];

int find(int a, int b, int index, int l, int r){
	
	// [a, b) の最小値を求める
	if(r <= a || b <= l){
		return INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	if(is_a[index]){
		return seg_tree[index];
	}
	int ret = INF;
	ret = min(ret, find(a, b, index * 2, l, (l + r) / 2));
	ret = min(ret, find(a, b, index * 2 + 1, (l + r) / 2, r));
	return ret;
}

int update(int a, int b, int index, int num, int l, int r){
	
	// [a, b) を num に変更する
	
	if(r <= a || b <= l){
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] = num;
		is_a[index] = true;
		return num;
	}
	int ret = INF;
	if(is_a[index]){
		is_a[index * 2] = true;
		seg_tree[index * 2] = seg_tree[index];
		is_a[index * 2 + 1] = true;
		seg_tree[index * 2 + 1] = seg_tree[index];
		is_a[index] = false;
		ret = seg_tree[index];
	}
	ret = min(ret, update(a, b, index * 2, num, l, (l + r) / 2));
	ret = min(ret, update(a, b, index * 2 + 1, num, (l + r) / 2, r));
	return seg_tree[index] = ret;
}

int main(){
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 0; i < TREE_SIZE; i++){
		seg_tree[i] = INF;
		is_a[i] = false;
	}
	is_a[1] = true;
	
	for(int i = 0; i < q; i++){
		long long int num, a, b, c;
		cin >> num;
		if(num == 0){
			cin >> a >> b >> c;
			update(a, b + 1, 1, c, 0, TREE_SIZE / 2);
		}else{
			cin >> a >> b;
			cout << find(a, b + 1, 1, 0, TREE_SIZE / 2) << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 12340