akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define OP ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;
typedef std::vector<int> vi;
typedef std::pair<int, int> pii;
const int inf = int(1e9);
const int mod = inf + 7;
const double PI = acos(-1.0);
using namespace std;
const int N = 1e5 + 155;
template<typename T>
inline void read(T&x){
    x=0;int f=1;char ch = getchar();
    while(ch<'0' ||ch>'9'){ if(ch=='-')f=-1;ch=getchar(); }
    while(ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
    x*=f;
}

void solve(){
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int j = 1; j <= n; j++) {
        int t = 0, i = j;
        while(i) {
            t += (i % 10), i /= 10;
        }
        if (a <= t && t <= b) ans += j;
    }
    cout << ans;
}
 
int main(){
    OP
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t = 1;
    while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	std::string s;
	std::cin >> s;
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (s[i] == s[j]) continue;
			for (int k = j + 1; k < n; k++) if (j - k != i - j && s[k] != s[i] && s[k] != s[j]) res++;
		}
	}
	printf("%" PRId64 "\n", res);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

bool p(string s, int l, int r) {
  while (l < r) {
    if (s[l] != s[r]) {
      return 0;
    }
    l++;
    r--;
  }
  return 1;
}

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

  string s;
  cin >> s;
  int n = (int) s.size(), h = n / 2;
  if (p(s, 0, h - 1) && p(s, h + 1, n - 1) && p(s, 0, n - 1)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }

}


Measured memory_bytes: 256
gets
h=Hash[gets.split.map(&:to_i).group_by{|e|e}]
ma=h.keys.max
mi=h.keys.min

puts (ma+1)/2 == mi && h[mi].size == (ma%2) + 1 && (mi+1..ma).all?{|e|h[e]&&h[e].size>=2} ? "Possible" : "Impossible"

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

bool dfs(pair<int, int> f, pair<int, int> s, int turn){

    //cout << turn << " " << f.first << " " << f.second << " " << s.first << " " << s.second << endl;


    if(f.first >= 5 && f.second >= 5) return false;

    if(s.first >= 5 && s.second >= 5) return true;

    //cout << turn << " " << f.first << " " << f.second << " " << s.first << " " << s.second << endl;

    if(turn){
        //先手の番
        pair<int, int> next_f;
        next_f = f;
        if(f.first < 5 && s.first < 5){
            pair<int, int> next_s;
            next_s = s;
            next_s.first += f.first;
            if(dfs(next_f, next_s, 0)){
                return true;    
            }
        }

        if(f.first < 5 && s.second < 5){
            pair<int, int> next_s;
            next_s = s;
            next_s.second += f.first;
            if(dfs(next_f, next_s, 0)){
                return true;
            }
        }


        if(f.second < 5 && s.first < 5){
            pair<int, int> next_s;
            next_s = s;
            next_s.first += f.second;
            if(dfs(next_f, next_s, 0)){
                return true;
            }
        }

        if(f.second < 5 && s.second < 5){
            pair<int, int> next_s;
            next_s = s;
            next_s.second += f.second;
            if(dfs(next_f, next_s, 0)){
                return true;
            }
        }
        
        return false;

    }else{
        //こうての番
        pair<int, int> next_s;
        next_s = s;
        if(f.first < 5 && s.first < 5){
            pair<int, int> next_f;
            next_f = f;
            next_f.first += s.first;
            if(!dfs(next_f, next_s, 1)){
                return false;    
            }
        }

        if(f.first < 5 && s.second < 5){
            pair<int, int> next_f;
            next_f = f;
            next_f.first += s.second;
            if(!dfs(next_f, next_s, 1)){
                return false;
            }
        }


        if(f.second < 5 && s.first < 5){
            pair<int, int> next_f;
            next_f = f;
            next_f.second += s.first;
            if(!dfs(next_f, next_s, 1)){
                return false;
            }
        }

        if(f.second < 5 && s.second < 5){
            pair<int, int> next_f;
            next_f = f;
            next_f.second += s.second;
            if(!dfs(next_f, next_s, 1)){
                return false;
            }
        }

        return true;
    }

}

int main(){

    pair<int, int> f;
    pair<int, int> s;
    cin >> f.first >> f.second;
    cin >> s.first >> s.second;

    bool ok = dfs(f, s, 1);
    if(ok) cout << "ISONO" << endl;
    else cout << "NAKAJIMA" << endl;

    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N; cin>>N;
    vector<ll> p(N+1);
    rep1(i,N) cin>>p[i];
    ll cnt=0,i=1;
    
    while(i<=N){
        if(p[i]==i){
            cnt++;
            i+=2;
        }
        else i++;
    }
    
    cout<<cnt<<endl;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
#include<unordered_map>
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;

int main() {
	cin >> N;
	ans = N % 2 ? 2 * N : N;
	cout << ans << endl;
}


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

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

  string s;
  cin >> s;

  int month = stoi(s.substr(5, 2));
  if (month > 4) cout << "TBD\n";
  else cout << "Heisei\n";

  return (0);
}


Measured memory_bytes: 3664
import sys

sys.setrecursionlimit(10 ** 6)
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]



def main():
    m=LI()
    k=m[0]
    n=m[1]
    a=LI()
    for i in range(n):
        if i!=0:
            a[i]-=a[0]
    a[0]=0;
    ans=k;
    for i in range(n-1):
        ans=min(ans, k-(a[i+1]-a[i]))
    ans=min(ans, a[n-1])
    print(ans)
main()


Measured memory_bytes: 25880
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] T = new int [N];
        int sum=0;
        for(int i=0; i<N; i++){
            T[i]=sc.nextInt();
            sum+=T[i];
        }
        int M = sc.nextInt();
        for(int i=0; i<M; i++){
            int P = sc.nextInt();
            int X = sc.nextInt();
            int ans = sum-T[P-1]+X;
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,s[100];

void push(int);
int pop(void);

int main(){
    int first,second;
    char stack[100];
    top=0;

    while(scanf("%s", stack)!=EOF){
        if(stack[0]=='+'){
            second=pop();
            first=pop();
            push(first+second);
        }else if(stack[0]=='-'){
            second=pop();
            first=pop();
            push(first-second);
        }else if(stack[0]=='*'){
            second=pop();
            first=pop();
            push(first*second);
        }else{
            push(atoi(stack));
        }
    }
    printf("%d\n",pop());
    return 0;
}

int pop(){
    top--;
    return s[top+1];
}

void push(int p){
    s[++top]=p;
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

int main(){
    ll n,k;cin>>n>>k;
    vector<ll> h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    if(k>=n){
        cout << 0 << endl;
        return 0;
    }
    ll ret = 0;
    sort(h.begin(),h.end());
    for(int i=0;i<n-k;i++) ret += h[i];
    cout << ret << endl;
}


Measured memory_bytes: 1792
from collections import deque
import sys
input = sys.stdin.buffer.readline

N, M = map(int, input().split())
adj = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
Q = int(input())
qs = []
for _ in range(Q):
    v, d, c = map(int, input().split())
    qs.append((v, d, c))
qs.reverse()

seen = [-1] * (N+1)
ans = [0] * (N+1)
for v0, d0, c in qs:
    if d0 > seen[v0]:
        que = deque()
        que.append((v0, d0))
        seen[v0] = d0
        while que:
            v, d = que.popleft()
            if ans[v] == 0:
                ans[v] = c
            if d > 0:
                for u in adj[v]:
                    if d-1 > seen[u]:
                        que.append((u, d-1))
                        seen[u] = d-1

for i in range(1, N+1):
    print(ans[i])


Measured memory_bytes: 89008
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();
        long K = sc.nextLong();
        int Q = sc.nextInt();
        int ans;

        long[] point = new long[N];

        for (int i = 0; i < Q; i++) {
            ans = sc.nextInt();
            point[ans-1] += 1;
        }

        for (int i = 0; i < N; i++) {
            System.out.println( (Q - (K - 1)) <= point[i] ? "Yes" : "No" );
        }
    }
}

Measured memory_bytes: 61408
#include<bits/stdc++.h>
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
double PI=acos(-1);
vector<int> adj[100005];
int dp[100005];
bool vis[100005];
int solve(int node){
    if(vis[node])
        return dp[node];
    vis[node]=1;
    int ret=1;
    for(auto v:adj[node])
        ret=max(ret,solve(v)+1);
    return dp[node]=ret;
}

int main(){
    int n,m,ans=0;cin>>n>>m;
    for(int i=0;i<100005;i++) dp[i]=1;
    for(int i=0;i<m;i++){
        int x,y;cin>>x>>y;
        adj[x].push_back(y);
    }
    for(int i=1;i<=n;i++) ans=max(ans,solve(i));
    cout<<ans-1<<'\n';







    return 0;
}


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

int main(int argc, char *argv[])
{
    int r;
	cin >> r;

	if (r >= 0 && r < 1200) {
		cout << "ABC" << endl;
	} else if (r >= 1200 && r < 2800) {
		cout << "ARC" << endl;
	} else {
		cout << "AGC" << endl;
	}

	return 0;
}


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

class UnionFind {
public:
vector<int> Parent;

UnionFind(int N) {
  Parent = vector<int>(N, -1);
}

int root(int A) {
  if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

int size(int A) {
  return -Parent[root(A)];
}

bool connect(int A, int B) {
  A = root(A);
  B = root(B);
  if (A == B) {
    return false;
  }
  if (size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
};


int main(){
  int n,m;
  cin >> n >> m;
  UnionFind uni(n);
  set<pair<int,int>> st;
  for (int i = 0; i < m; i++)
  {
    int a,b;
    cin >> a >> b;
    st.emplace(a,b);
  }

  for(auto p:st){
    uni.connect(p.first-1, p.second-1);
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    ans = max(ans,uni.size(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 13512
#include <iostream>

using namespace std;

int main (){
  int A,B,X;

  cin >> A >> B>> X;

  if(A <= X){
    if((A+B) >= X){
      cout << "YES" << endl;
    }
    else cout << "NO" << endl;
  }
  else cout << "NO" << endl;

  return 0;
}


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

struct Edge {
    int from, to, len;
    Edge(int from, int to, int len) : from(from), to(to), len(len) {}
};

vector<vector<Edge>> graph;
vector<int> ans;

void dfs(int v, int c = 0, int p = -1) {
    ans.at(v) = c;
    for (auto e : graph.at(v)) {
        if (e.to == p) continue;
        if (e.len % 2 == 0)
            dfs(e.to, c, v);
        else
            dfs(e.to, 1 - c, v);
    }
}

int main() {
    int N;
    cin >> N;
    graph = vector<vector<Edge>>(N);
    ans = vector<int>(N);
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        graph.at(u).push_back(Edge(u, v, w));
        graph.at(v).push_back(Edge(v, u, w));
    }
    dfs(0);
    for (int i = 0; i < N; i++) {
        cout << ans.at(i) << endl;
    }

    return 0;
}


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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int n; string s;
    cin >> n >> s;
    int ans = 0, x = 0;
    for(char c : s){
        if(c == 'I'){
            x++;
        }else{
            x--;
        }
        ans = max(ans, x);
    }
    cout << ans << endl;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 1010;
int n,m, dist[maxn], pre[maxn]; set<int> G[maxn];

void bfs(const int x)
{
    FOR(i,1,n+1)
        dist[i] = inf, pre[i] = 0;
    dist[x] = 0;
    queue<int> Q; Q.push(x);
    while (Q.size()) {
        const int u = Q.front(); Q.pop();
        FOR_ALL(v,G[u]) {
            const int d = dist[u]+1;
            if (d < dist[*v]) {
                dist[*v] = d; Q.push(*v); pre[*v] = u;
            }
        }
    }   
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n >> m) {
        FOR(i,1,n+1)
            G[i].clear();
        FOR(_,0,m) {
            int u,v; cin >> u >> v;
            G[u].insert(v);
        }
        VI ans;
        FOR(i,1,n+1) {
            bfs(i);
            int x = 0;
            FOR(j,1,n+1) if (dist[j] < inf && in_(i,G[j])) {
                if (!x || dist[j] < dist[x])
                    x = j;
            }
            if (x) {
                VI res = {x};
                while (pre[x]) {
                    res.push_back(pre[x]); x = pre[x];
                }
                if (ans.empty() || ans.size() > res.size())
                    ans = res;
            }
        }
        if (ans.size()) {
            cout << ans.size() << endl;
            FOR_ALL(a,ans)
                cout << *a << endl;
        }
        else
            cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <iterator>

using namespace std;

int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<pair<int,int> >jobs ;
    for(int i = 0;i  < N; i++){
        int a,b;
        cin >> a >> b;
        auto tmp = pair(b,a);
        jobs.push_back(tmp);
    }
    sort(jobs.begin(), jobs.end());
    
    int time = 0;
    for(int i =0; i < N; i++){
        time += jobs[i].second;
        if(time > jobs[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
    
}


Measured memory_bytes: 5352
#include <iostream>
#include <map>

using namespace std;

struct Node
{
    int parent;
    int depth;
};

Node roads[200'000];
Node rails[200'000];

int findRoot(const Node *nodes, int x)
{
    int curr = x;
    while (curr != nodes[curr].parent)
    {
        curr = nodes[curr].parent;
    }
    return curr;
}

void mergeSet(Node *nodes, int r0, int r1)
{
    if (r0 == r1)
    {
        return;
    }
    if (nodes[r0].depth < nodes[r1].depth)
    {
        nodes[r0].parent = r1;
    }
    else if (nodes[r0].depth > nodes[r1].depth)
    {
        nodes[r1].parent = r0;
    }
    else
    {
        nodes[r0].parent = r1;
        nodes[r1].depth++;
    }
}

int main()
{
    int N, K, L;
    cin >> N >> K >> L;

    for (int i = 0; i < N; i++)
    {
        rails[i].parent = roads[i].parent = i;
        rails[i].depth = roads[i].depth = 0;
    }

    for (int i = 0; i < K; i++)
    {
        int p, q;
        cin >> p >> q;
        p--;
        q--;

        int pr = findRoot(roads, p);
        int qr = findRoot(roads, q);
        mergeSet(roads, pr, qr);
    }

    for (int i = 0; i < L; i++)
    {
        int r, s;
        cin >> r >> s;
        r--;
        s--;

        int rr = findRoot(rails, r);
        int sr = findRoot(rails, s);
        mergeSet(rails, rr, sr);
    }

    map<pair<int, int>, int> sNum;
    for (int i = 0; i < N; i++)
    {
        pair<int, int> p = {findRoot(roads, i), findRoot(rails, i)};
        sNum[p]++;
    }

    for (int i = 0; i < N; i++)
    {
        pair<int, int> p = {findRoot(roads, i), findRoot(rails, i)};

        //cout << "p: " << p.first << "," << p.second << " ";
        cout << sNum[p] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 15104
#include <iostream>
#include <cstdio>
#include <string>
#include <map>
#include <algorithm>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  map<string, int> m;
  
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(begin(s), end(s));
    if (m.count(s) != 0) m[s] += 1;
    else m[s] = 1;
  }

  long long int ans = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    long long int sum = 0;
    for (int i = 2; i <= it->second; i++) sum += i - 1;
    ans += sum;
  }
  printf("%lld\n", ans);

  return 0;
}


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

using namespace std;

int n, k;
vector<int> a;
vector<int> dp;

int solve(int rest) {
	if (dp[rest] != -1) return dp[rest];
	for (int i = 0; i < n; ++i) {
		if (rest < a[i]) continue;
		if (!solve(rest - a[i])) return dp[rest] = 1;
	}
	return dp[rest] = 0;
}

int main() {
	cin >> n >> k;
	a.resize(n);
	dp.assign(k + 1, -1);
	for (int i = 0; i < n; ++i) cin >> a[i];
	if (solve(k)) cout << "First" << endl;
	else cout << "Second" << endl;

	return 0;
}

Measured memory_bytes: 5376
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			String line = sc.nextLine();
			String answer = "";
			int length = line.length();
			for (int i = 0; i < length; i++) {
				char ch = line.charAt(i);
				if (Character.isLowerCase(ch)) {
					ch = Character.toUpperCase(ch);
					System.out.print(ch);
				} else {
					ch = Character.toLowerCase(ch);
					System.out.print(ch);
				}
			}
			System.out.println(answer);
		}
	}

}


Measured memory_bytes: 26996
def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)

N=int(input())
A=[int(i) for i in input().split()]

L = [0 for i in range(N)]
R = [0 for i in range(N)]

for i in range(1,N):
    L[i] = gcd(L[i-1],A[i-1])

for i in range(N-1)[::-1]:
    R[i] = gcd(R[i+1],A[i+1])

Z=[gcd(L[i],R[i]) for i in range(N)]

print(max(Z))

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

static const ll maxx = 1e9;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, d, a;
    cin >> n >> d >> a;
    vector<pair<ll, ll>> m(n);
    rep(i, n) {
        cin >> m[i].first >> m[i].second;
    }

    sort(m.begin(), m.end());
    d = d * 2;
    ll tot = 0;
    queue<pair<ll, ll>> q;
    ll ans = 0;
    
    rep(i, n) {
        ll x = m[i].first;
        ll h = m[i].second;
        while(q.size() && q.front().first < x) {
            tot -= q.front().second;
            q.pop();
        }
        h -= tot;
        if (h > 0) {
            ll num = (h + a - 1) / a;
            ans += num;
            ll damage = num * a;
            tot += damage;
            q.emplace(x + d, damage);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

typedef long long i64;

string s;
int main()
{
    cin >> s;

    int result = 0;

    int sum = 0;

    reverse(s.begin(),s.end());

    for(int i = 0;i < s.size();i++)
    {
        int n = s[i] - '0';
        sum += n;
    }
    result = sum;

    for(int i = 0;i < s.size() - 1;i++)
    {
        int now = s[i] - '0';
        int next = s[i + 1] - '0';
        if(next != 0)
        {
            ///now digit to 9
            sum -= now;
            sum += 9;
            next -= 1;
            s[i + 1] = next + '0';
            sum -= 1;
            result = max(result , sum);
        }
        else
        {
            sum -= now;
            sum += 9;
            s[i + 1] = '9';
            sum += 9;
        }
    }

    result = max(result , (int)s.size() * 9 - 9);

    cout << result << endl;




}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main(){
	int n;
	cin >> n;
	vector<int> a, b;
	int res = 0;
	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		res += abs(num);
		if(num <= 0) b.push_back(num);
		else a.push_back(num);
	}
	sort(a.begin(), a.end());
	sort(b.begin(), b.end(), greater<int>());
	if(a.size() == n){
		cout << res - 2 * a[0] << endl;
		int cur = a[0];
		for(int i = 1; i < n - 1; i++){
			cout << cur << " " << a[i] << endl;
			cur = cur - a[i];
		}
		cout << a[n - 1] << " " << cur << endl;
	}else if(b.size() == n){
		cout << res + 2 * b[0] << endl;
		int cur = b[0];
		for(int i = 1; i < n; i++){
			cout << cur << " " << b[i] << endl;
			cur = cur - b[i];
		}
	}else{
		cout << res << endl;
		int cur = b[0];
		for(int i = 1; i < a.size(); i++){
			cout << cur << " " << a[i] << endl;
			cur = cur - a[i];
		}
		cout << a[0] << " " << cur << endl;
		cur = a[0] - cur;
		for(int i = 1; i < b.size(); i++){
			cout << cur << " " << b[i] << endl;
			cur = cur - b[i];
		}
	}
	return 0;
}


Measured memory_bytes: 2424
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <array>
#include <utility>
#include <valarray>

using namespace std;

int main()
{
    int N, K;
    scanf("%d %d\n", &N, &K);
    int need = 0;
    vector<int> A; A.reserve(N);
    for (int i = 0; i < N; ++i){
        int Ai;
        scanf("%d", &Ai); getchar();
        if (Ai >= K){
            ++need;
        }else{
            A.emplace_back(Ai);
        }
    }
    sort(A.begin(), A.end(), greater<int>());
    int last_i = -1;
    unordered_set<int> sum;
    sum.emplace(0);
    for (int i = 0; i < A.size(); ++i){
        unordered_set<int> next_sum;
        for (auto& s : sum){
            const int temp = s + A[i];
            if (sum.count(temp) == 0){
                if (temp >= K){
                    last_i = i;
                }else{
                    next_sum.emplace(temp);
                }
            }
        }
        sum.insert(next_sum.begin(), next_sum.end());
    }
    printf("%d\n", N - need - (last_i + 1));
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
using P = pair<int,int>;
int main(){
  int a,b;
  vector<int> c(102);
 cin >> a>> b;
 for(int i= 0;i<b;i++){
    int p;
    cin >> p;
    c[p]=1;
 }
P ans(99999,-1);
for(int i= 0;i<=101;++i){
   if(c[i]==1) continue;
   int dif = abs(a-i);
   ans = min(ans,P(dif,i));
}
cout << ans.second << endl;
return 0;
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.nextLine();
    String T = sc.nextLine();
    //SとTの長さsl tl
    int sl = S.length();
    int tl = T.length();
    //一致していない文字数を数えmに格納。missよりmが小さければmissを更新する
    int miss = 1000;
    int m = 0;
    
    if(S.contains(T)){
      miss = 0;
    }else{
        for(int i = 0; i <= sl - tl; i++){
            for(int j = 0; j < tl; j++){
                if((S.substring(i + j, i + j + 1)).equals(T.substring(j, j + 1)) == false){
                    m += 1;
                }
            }
            if(miss > m){
                miss = m;
            }
            m = 0;
        }
    }
    System.out.println(miss);
  }
}

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

int main()
{
  int h, w;
  while (1) {
    cin >> h >> w;
    if (h == 0 && w == 0) break;
    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        if ((i+j)%2==0)
          printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 3076
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	
	string n;
	cin>>n;
	int i=0;
	if(n[0]=='A')
	{
		i=1;
	}
	int y=0;
	if(i==1)
	{
		for(int p=2;p<n.size()-1;p++)
		{
			if(n[p]=='C')
			{
			    y++;	
			}
		}
	}
	int num=0;
	if(y==1)
	{
	for(int o=1;o<n.size();o++)
	{
		if(n[o]=='C'||n[o]>=97)
		{
			num++;
		}   
	}
}
	if(num==n.size()-1)
		{
			cout<<"AC";
		}
		else
		cout<<"WA";
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r = 0;
	deque<char> d;
	rep(i, s.size()) {
		if(s[i] == '(') d.push_back('('), r++;
		else {
			if(r > 0) d.push_back(')'), r--;
			else d.push_front('('), d.push_back(')');
		}
	}
	rep(i, r) d.push_back(')');
	rep(i, d.size()) cout << d[i];
	cout << endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

var board [8][8]bool
var rl [8]bool

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

func printBoard() {
	for i := 0; i < 8; i++ {
		for j := 0; j < 8; j++ {
			if board[i][j] {
				fmt.Print("Q")
			} else {
				fmt.Print(".")
			}

		}
		fmt.Print("\n")
	}

}

func check(x, y int) bool {
	if x <= -1 || x >= 8 || y <= -1 || y >= 8 {
		panic("error")

	}
	for i := 0; i < 8; i++ {
		if board[x][i] {
			return false
		}
		if board[i][y] {
			return false
		}
	}
	for i := 0; i < 8; i++ {
		if x+i >= 8 || y+i >= 8 {
			break
		}
		if board[x+i][y+i] {
			return false
		}
	}
	for i := 0; i < 8; i++ {
		if x-i <= -1 || y-i <= -1 {
			break
		}
		if board[x-i][y-i] {
			return false
		}
	}
	for i := 0; i < 8; i++ {
		if x+i >= 8 || y-i <= -1 {
			break
		}
		if board[x+i][y-i] {
			return false
		}
	}
	for i := 0; i < 8; i++ {
		if x-i <= -1 || y+i >= 8 {
			break
		}
		if board[x-i][y+i] {
			return false
		}
	}
	return true
}

func dfs(N int) bool {
	if N == 8 {
		return true
	}

	for i := 0; i < 8; i++ {
		if rl[N] {
			return dfs(N + 1)
		}

	}

	for i := 0; i < 8; i++ {
		if check(N, i) {
			fill(N, i)
			if !dfs(N + 1) {
				unfill(N, i)
				continue
			} else {
				return true
			}
		}

	}

	return false

}

func unfill(x, y int) {
	board[x][y] = false
}

func fill(x, y int) {

	board[x][y] = true

}

func main() {
	sc.Split(bufio.ScanWords)

	queens := next()
	for n := 0; n < queens; n++ {
		x, y := next(), next()
		rl[x] = true
		fill(x, y)
	}

	dfs(0)

	printBoard()
}



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

int main() {
	int n1=0,n2=0,temp,num;
	bool flg=true;
	cin>>num;
	while(num--){
		for(int i=0;i<10;i++){
			cin>>temp;
			if(temp>n1) n1=temp;
			else if(temp>n2) n2=temp;
			else flg=false;
		} n1=0;n2=0;
		if(flg) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}	return 0;
}

Measured memory_bytes: 1152
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt(),
			w = sc.nextInt();
		String[] s = new String[h];
		for(int i = 0; i < h; i++) {
			s[i] = sc.next();
		}

		int[] uD = {1, 0, -1, 0};
		int[] lR = {0, 1, 0, -1};
		
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if(s[i].charAt(j) == '#'){
					for(int k = 0; k < 4; k++) {
							if(0 <= i + uD[k] && i + uD[k] < h
								&& 0 <= j + lR[k] && j + lR[k] < w
								&& s[i + uD[k]].charAt(j + lR[k]) == '#') {
								break;
							}
							if(k == 3) {
								System.out.println("No");
								return;
							}
					}		
				}

			}
		}
			System.out.println("Yes");
	}
}

Measured memory_bytes: 21972
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
#      .      '                    Udit Gupta @luctivud         ,              
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                            ##     ##  #######  # #  ######
                            ##     ##  ##   ##  ###    ##
                            ##     ##  ##    #  # #    ##
                            #########  #######  # #    ##
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

import sys
import math as mt
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_array(): return list(map(int, sys.stdin.readline().strip().split()))

def printwsp(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end="tst, ")

MOD = int(1e9+7); BABYMOD = 998244353;
# ################################ HELPER PROGRAMS USED ###################################
# ################################## MAIN STARTS HERE #####################################
# for _testcases_ in range(int(input())):
x = int(input())
i = 0
se = set()
d = {}
while(True):
    num = i ** 5
    if num > 1e18 :
        break
    d[num] = i
    se.add(num)
    i += 1
# print(se)
for i in se:
    y = i + x
    if y in se:
        # print("s")
        a = max(d[i], d[y]) 
        b = min(d[i], d[y])
        print(a, b)
        break
    y = abs(i-x)
    if y in se:
        # a = max(d[i], d[y]) 
        # b = min(d[i], d[y])
        print(d[i], -d[y])
        break

# #########################################################################################
'''
THE LOGIC AND APPROACH WAS DEVELOPED BY ME @luctivud.
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
PLEASE DO NOT PLAGIARISE.
'''

Measured memory_bytes: 65812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 1e5+10;
const int inf = 0x3f3f3f3f;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll n,m;
	cin>>m>>n;
	rep(i,1,n) {
		ll x;
		cin>>x;
		m-=x;
	}
	if(m<0) cout<<-1<<'\n';
	else cout<<m<<'\n';
	return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=INF;

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  vector<string> a(n);
  vector<ll> b(n,0);
  rep(i,n) cin >> a[i];
  rep(i,n){
      ll u=9;
      bool t=false;
      rep(j,a[i].size()){
          if (t) u--;
          if (a[i][j]!='.') {b[i]*=10;b[i]+=a[i][j]-'0';}
          else t=true;
      }
      b[i]*=Pow(10,u);
  }
  vector<vector<ll>> c(20,vector<ll>(20,0));
  ll ans=0;
  rep(i,n){
      int c2=0,c5=0;
      while(true){
          if(b[i]%2==0) c2++;
          else break;
          b[i]/=2;
      }
      while(true){
          if (b[i]%5==0) c5++;
          else break;
          b[i]/=5;
      }
      ans+=c[max(0,18-c2)][max(0,18-c5)];
      rep(j,min(c2+1,20)){
          rep(k,min(c5+1,20)){
              c[j][k]++;
          }
      }
  }
  cout << ans << endl;
}


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

# define NMAX 1000000001

// void change(int b, int c, std::vector<int> &seq){
//     for(int i=0; i < b; i++){
//         if(seq.at(i) < c){
//             seq.at(i) = c;
//         }else{
//             return;
//         }
//     }
// }
//
// void map_change(){
//
// }

int main(){
    int N, M;
    cin >> N >> M;
    std::vector<int> seq(N);
    for(int i=0; i < N; i++){
        cin >> seq.at(i);
    }
    vector<std::vector<int> > ope(M, vector<int>(2));
    std::map<int, int> ope_map;
    // for(int i=0; i < M; i++){
    //     cin >> ope.at(i).at(0) >> ope.at(i).at(1);
    // }
    int a, b;
    for(int i=0; i < M; i++){
        cin >> a >> b;
        if(ope_map.count(b)){
            ope_map[b] += a;
        }else{
            ope_map[b] = a;
        }

    }
    sort(seq.begin(), seq.end());
    std::vector<int> ope_seq(N, 0);
    int pointer = 0;
    for (map<int, int>::reverse_iterator iter = ope_map.rbegin(); iter != ope_map.rend(); ++iter){
        // cout << iter->first << endl;
        int len = pointer + iter->second;
        for(int i=pointer; i < len; i++){
            ope_seq.at(i) = iter->first;
            // cout << iter->first << endl;
            pointer ++;
            if(pointer >= N){
                break;
            }
        }
        if(pointer >= N){
            break;
        }
    }
    sort(ope_seq.begin(), ope_seq.end());
    // for(int i=0; i < N; i++){
    //     cout << seq.at(i) << " ";
    // }
    // cout << endl;
    // for(int i=0; i < N; i++){
    //     cout << ope_seq.at(i) << " ";
    // }
    // cout << endl;
    std::vector<int>::iterator iter_ope = ope_seq.end() - 1;
    std::vector<int>::iterator iter_seq = seq.end() - 1;
    long sum = 0;
    for(int i=0; i < N; i++){
        if(*iter_ope > *iter_seq){
            sum += *iter_ope;
            iter_ope --;
        }else{
            sum += *iter_seq;
            iter_seq --;
        }
    }


    // for(int i=0; i < M; i++){
    //     change(ope.at(i).at(0), ope.at(i).at(1), seq);
    // }
    // long sum = accumulate(seq.begin(), seq.end(), 0);
    cout << sum << endl;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  double pos[N][2]; rep(i,N) cin >> pos[i][0] >> pos[i][1];
  double result = 0;
  int v[N]; rep(i,N) v[i] = i;
  do {
    rep(i,N-1) {
      double dx = pos[v[i]][0]-pos[v[i+1]][0];
      double dy = pos[v[i]][1]-pos[v[i+1]][1];
      result += sqrt(pow(dx,2)+pow(dy,2));
    }
  } while( next_permutation(v, v+N) );
  rep(i,N) result /= i+1;
  cout << fixed << setprecision(10) << result << endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

int N, K;

int main(){
    cin >> N >> K;
    ll dp[N];
    
    vector<ll> h(N);
    REP(i,N)cin >> h[i];
    REP(i,N)dp[i]=INF;
    
    dp[0]=0;
    FOR(i,1,N){
      FOR(j,1,K+1){
        if(i-j<0)break;
        if(dp[i] > (dp[i-j] + abs(h[i] - h[i-j]))){
          dp[i] = (dp[i-j] + abs(h[i] - h[i-j]));
        }
      }
    }
    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    int X, Y;
    cin >> X >> Y;
    bool check = false;

    for(int i = 0; i <= 100; i++) {
        for(int j = 0; j <= 100; j++) {
            if ((i + j == X) && (2*i + 4*j == Y)) {
                check = true;
            }
        }
    }
    if(check) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int add(int a, int b) {
	a += b;
	if (a >= mod) {
		return a - mod;
	}
	return a; 
}
void add_self(int& a, int b) {
	a = add(a, b);
}
int mult(int a, int b) {
	return 1ll * a * b % mod;
}
void mult_self(int& a, int b) {
	a = mult(a, b);
}
int bin_pow(int a, int b) {
	if (b == 0) {
		return 1;
	}
	if (b % 2 == 0) {
		return bin_pow(mult(a, a), b / 2);
	}
	return mult(a, bin_pow(a, b - 1));
}
int inv(int a) {
	return bin_pow(a, mod - 2);
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	//~ int lcm = a[0];
	//~ ll lcm2 = a[0];
	map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		int memo = a[i];
		for (int j = 2; j * j <= a[i]; ++j) {
			if (a[i] % j == 0) {
				int cnt = 0;
				while (a[i] % j == 0) {
					a[i] /= j;
					++cnt;
				}
				mp[j] = max(mp[j], cnt);
			}
		}
		if (a[i] != 1) {
			mp[a[i]] = max(mp[a[i]], 1);
		}
		a[i] = memo;
		//~ lcm2 = lcm2 / g * a[i];
	}
	int sum = 0;
	int lcm = 1;
	for (auto p : mp) {
		mult_self(lcm, bin_pow(p.first, p.second));
	}
	debug(lcm);
	for (int i = 0; i < n; ++i) {
		add_self(sum, mult(lcm, inv(a[i])));
		//~ sum += lcm2 / a[i];
		//~ sum %= mod;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

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

  vector<int> v(n);
  long long arai = 0;
  for(int i = 0; i < n; i++){
    cin >> v[i];
    arai += v[i];
  }
  arai -= v[0];

  long long sunu = v[0];
  long long ans = abs(sunu - arai);
  for(int i = 1; i < n - 1; i++){
    sunu += v[i];
    arai -= v[i];
    if(ans < abs(sunu - arai)) ans = ans;
    else ans = abs(sunu - arai);
  }
  cout << ans << endl;

  return 0;
}

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

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 DECIM8  fixed<<setprecision(8) 
#define SZ(a) int((a).size())
#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);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

using namespace std;
int main(void)
{
  for(;;){
    int n,m,p,sum=0,div;
    cin >> n >> m >> p;
    if(!n&&!m&&!p) return 0;
    REP(i,n){
      int tmp;
      cin >> tmp;
      sum+=tmp;
      if(i+1==m) div=tmp;
    }
    if(div==0) sum=0;
    else sum=sum*(100-p)/div;
    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main(){
	int n;
	cin>>n;
	int res = inf;
	long long sum = 0;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
		sum += vec[i];
	}
	vector<int> table(n, 0);
	table[0] = vec[0];
	for(int i = 1; i < n; ++i)table[i] = table[i - 1] + vec[i];
	for(int i = 0; i < n; ++i){
		int s = table[i];
		int r = sum - table[i];
		res = min(res, abs(s - r));
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
using namespace std;
int  gcd(int a, int b) {
	if (a < b) gcd(b, a);
	int r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
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;
}
int cntb = 0;
int cntw = 0;
int h, w;
int field[403][403];
int siyouzumi[403][403];
void dfs(int nowh,int noww,int bw) {
	if (siyouzumi[nowh][noww])return;
	siyouzumi[nowh][noww] = 1;
	if (bw == 0) {
		cntb += 1;
	}
	else cntw += 1;
	if (nowh > 0) {
		if (field[nowh - 1][noww] == 1 - bw&&siyouzumi[nowh - 1][noww] == 0) {
			dfs(nowh - 1, noww, 1 - bw);
		}
	}
	if (nowh < h - 1) {
		if (field[nowh + 1][noww] == 1 - bw&&siyouzumi[nowh + 1][noww] == 0) {
			dfs(nowh + 1, noww, 1 - bw);
		}
	}
	if (noww < w - 1) {
		if (field[nowh][noww+1] == 1 - bw&&siyouzumi[nowh][noww+1] == 0) {
			dfs(nowh, noww+1, 1 - bw);
		}
	}
	if (noww > 0) {
		if (field[nowh][noww-1] == 1 - bw&&siyouzumi[nowh][noww-1] == 0) {
			dfs(nowh, noww-1, 1 - bw);
		}
	}
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> h >> w;
	string s;
	for (int i = 0; i < h; i++) {
		cin >> s;
		for (int j = 0; j < w; j++) {
			if (s[j] == '#')field[i][j] = 0;
			else field[i][j] = 1;
		}
	}
	for (int i = 0; i < 403; i++) {
		for (int j = 0; j < 403; j++) {
			siyouzumi[i][j] = 0;
		}
	}
	long long ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (siyouzumi[i][j] == 0) {
				dfs(i, j, field[i][j]);
				ans += (long long)cntb*cntw;
				cntb = 0;
				cntw = 0;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 14080